// Code generated by smithy-go-codegen DO NOT EDIT. package cloudformation import ( "context" "errors" "fmt" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" smithy "github.com/aws/smithy-go" "github.com/aws/smithy-go/middleware" smithytime "github.com/aws/smithy-go/time" smithyhttp "github.com/aws/smithy-go/transport/http" smithywaiter "github.com/aws/smithy-go/waiter" "github.com/jmespath/go-jmespath" "time" ) // Returns the description for the specified stack; if no stack name was // specified, then it returns the description for all the stacks created. If the // stack doesn't exist, an ValidationError is returned. func (c *Client) DescribeStacks(ctx context.Context, params *DescribeStacksInput, optFns ...func(*Options)) (*DescribeStacksOutput, error) { if params == nil { params = &DescribeStacksInput{} } result, metadata, err := c.invokeOperation(ctx, "DescribeStacks", params, optFns, c.addOperationDescribeStacksMiddlewares) if err != nil { return nil, err } out := result.(*DescribeStacksOutput) out.ResultMetadata = metadata return out, nil } // The input for DescribeStacks action. type DescribeStacksInput struct { // A string that identifies the next page of stacks that you want to retrieve. NextToken *string // If you don't pass a parameter to StackName , the API returns a response that // describes all resources in the account. This requires ListStacks and // DescribeStacks permissions. The IAM policy below can be added to IAM policies // when you want to limit resource-level permissions and avoid returning a response // when no parameter is sent in the request: { "Version": "2012-10-17", // "Statement": [{ "Effect": "Deny", "Action": "cloudformation:DescribeStacks", // "NotResource": "arn:aws:cloudformation:*:*:stack/*/*" }] } The name or the // unique stack ID that's associated with the stack, which aren't always // interchangeable: // - Running stacks: You can specify either the stack's name or its unique stack // ID. // - Deleted stacks: You must specify the unique stack ID. // Default: There is no default value. StackName *string noSmithyDocumentSerde } // The output for a DescribeStacks action. type DescribeStacksOutput struct { // If the output exceeds 1 MB in size, a string that identifies the next page of // stacks. If no additional page exists, this value is null. NextToken *string // A list of stack structures. Stacks []types.Stack // Metadata pertaining to the operation's result. ResultMetadata middleware.Metadata noSmithyDocumentSerde } func (c *Client) addOperationDescribeStacksMiddlewares(stack *middleware.Stack, options Options) (err error) { err = stack.Serialize.Add(&awsAwsquery_serializeOpDescribeStacks{}, middleware.After) if err != nil { return err } err = stack.Deserialize.Add(&awsAwsquery_deserializeOpDescribeStacks{}, middleware.After) if err != nil { return err } if err = addSetLoggerMiddleware(stack, options); err != nil { return err } if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { return err } if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { return err } if err = addResolveEndpointMiddleware(stack, options); err != nil { return err } if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { return err } if err = addRetryMiddlewares(stack, options); err != nil { return err } if err = addHTTPSignerV4Middleware(stack, options); err != nil { return err } if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { return err } if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { return err } if err = addClientUserAgent(stack, options); err != nil { return err } if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { return err } if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { return err } if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeStacks(options.Region), middleware.Before); err != nil { return err } if err = awsmiddleware.AddRecursionDetection(stack); err != nil { return err } if err = addRequestIDRetrieverMiddleware(stack); err != nil { return err } if err = addResponseErrorMiddleware(stack); err != nil { return err } if err = addRequestResponseLogging(stack, options); err != nil { return err } return nil } // DescribeStacksAPIClient is a client that implements the DescribeStacks // operation. type DescribeStacksAPIClient interface { DescribeStacks(context.Context, *DescribeStacksInput, ...func(*Options)) (*DescribeStacksOutput, error) } var _ DescribeStacksAPIClient = (*Client)(nil) // DescribeStacksPaginatorOptions is the paginator options for DescribeStacks type DescribeStacksPaginatorOptions struct { // Set to true if pagination should stop if the service returns a pagination token // that matches the most recent token provided to the service. StopOnDuplicateToken bool } // DescribeStacksPaginator is a paginator for DescribeStacks type DescribeStacksPaginator struct { options DescribeStacksPaginatorOptions client DescribeStacksAPIClient params *DescribeStacksInput nextToken *string firstPage bool } // NewDescribeStacksPaginator returns a new DescribeStacksPaginator func NewDescribeStacksPaginator(client DescribeStacksAPIClient, params *DescribeStacksInput, optFns ...func(*DescribeStacksPaginatorOptions)) *DescribeStacksPaginator { if params == nil { params = &DescribeStacksInput{} } options := DescribeStacksPaginatorOptions{} for _, fn := range optFns { fn(&options) } return &DescribeStacksPaginator{ options: options, client: client, params: params, firstPage: true, nextToken: params.NextToken, } } // HasMorePages returns a boolean indicating whether more pages are available func (p *DescribeStacksPaginator) HasMorePages() bool { return p.firstPage || (p.nextToken != nil && len(*p.nextToken) != 0) } // NextPage retrieves the next DescribeStacks page. func (p *DescribeStacksPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeStacksOutput, error) { if !p.HasMorePages() { return nil, fmt.Errorf("no more pages available") } params := *p.params params.NextToken = p.nextToken result, err := p.client.DescribeStacks(ctx, ¶ms, optFns...) if err != nil { return nil, err } p.firstPage = false prevToken := p.nextToken p.nextToken = result.NextToken if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { p.nextToken = nil } return result, nil } // StackCreateCompleteWaiterOptions are waiter options for // StackCreateCompleteWaiter type StackCreateCompleteWaiterOptions struct { // Set of options to modify how an operation is invoked. These apply to all // operations invoked for this client. Use functional options on operation call to // modify this list for per operation behavior. APIOptions []func(*middleware.Stack) error // MinDelay is the minimum amount of time to delay between retries. If unset, // StackCreateCompleteWaiter will use default minimum delay of 30 seconds. Note // that MinDelay must resolve to a value lesser than or equal to the MaxDelay. MinDelay time.Duration // MaxDelay is the maximum amount of time to delay between retries. If unset or // set to zero, StackCreateCompleteWaiter will use default max delay of 120 // seconds. Note that MaxDelay must resolve to value greater than or equal to the // MinDelay. MaxDelay time.Duration // LogWaitAttempts is used to enable logging for waiter retry attempts LogWaitAttempts bool // Retryable is function that can be used to override the service defined // waiter-behavior based on operation output, or returned error. This function is // used by the waiter to decide if a state is retryable or a terminal state. By // default service-modeled logic will populate this option. This option can thus be // used to define a custom waiter state with fall-back to service-modeled waiter // state mutators.The function returns an error in case of a failure state. In case // of retry state, this function returns a bool value of true and nil error, while // in case of success it returns a bool value of false and nil error. Retryable func(context.Context, *DescribeStacksInput, *DescribeStacksOutput, error) (bool, error) } // StackCreateCompleteWaiter defines the waiters for StackCreateComplete type StackCreateCompleteWaiter struct { client DescribeStacksAPIClient options StackCreateCompleteWaiterOptions } // NewStackCreateCompleteWaiter constructs a StackCreateCompleteWaiter. func NewStackCreateCompleteWaiter(client DescribeStacksAPIClient, optFns ...func(*StackCreateCompleteWaiterOptions)) *StackCreateCompleteWaiter { options := StackCreateCompleteWaiterOptions{} options.MinDelay = 30 * time.Second options.MaxDelay = 120 * time.Second options.Retryable = stackCreateCompleteStateRetryable for _, fn := range optFns { fn(&options) } return &StackCreateCompleteWaiter{ client: client, options: options, } } // Wait calls the waiter function for StackCreateComplete waiter. The maxWaitDur // is the maximum wait duration the waiter will wait. The maxWaitDur is required // and must be greater than zero. func (w *StackCreateCompleteWaiter) Wait(ctx context.Context, params *DescribeStacksInput, maxWaitDur time.Duration, optFns ...func(*StackCreateCompleteWaiterOptions)) error { _, err := w.WaitForOutput(ctx, params, maxWaitDur, optFns...) return err } // WaitForOutput calls the waiter function for StackCreateComplete waiter and // returns the output of the successful operation. The maxWaitDur is the maximum // wait duration the waiter will wait. The maxWaitDur is required and must be // greater than zero. func (w *StackCreateCompleteWaiter) WaitForOutput(ctx context.Context, params *DescribeStacksInput, maxWaitDur time.Duration, optFns ...func(*StackCreateCompleteWaiterOptions)) (*DescribeStacksOutput, error) { if maxWaitDur <= 0 { return nil, fmt.Errorf("maximum wait time for waiter must be greater than zero") } options := w.options for _, fn := range optFns { fn(&options) } if options.MaxDelay <= 0 { options.MaxDelay = 120 * time.Second } if options.MinDelay > options.MaxDelay { return nil, fmt.Errorf("minimum waiter delay %v must be lesser than or equal to maximum waiter delay of %v.", options.MinDelay, options.MaxDelay) } ctx, cancelFn := context.WithTimeout(ctx, maxWaitDur) defer cancelFn() logger := smithywaiter.Logger{} remainingTime := maxWaitDur var attempt int64 for { attempt++ apiOptions := options.APIOptions start := time.Now() if options.LogWaitAttempts { logger.Attempt = attempt apiOptions = append([]func(*middleware.Stack) error{}, options.APIOptions...) apiOptions = append(apiOptions, logger.AddLogger) } out, err := w.client.DescribeStacks(ctx, params, func(o *Options) { o.APIOptions = append(o.APIOptions, apiOptions...) }) retryable, err := options.Retryable(ctx, params, out, err) if err != nil { return nil, err } if !retryable { return out, nil } remainingTime -= time.Since(start) if remainingTime < options.MinDelay || remainingTime <= 0 { break } // compute exponential backoff between waiter retries delay, err := smithywaiter.ComputeDelay( attempt, options.MinDelay, options.MaxDelay, remainingTime, ) if err != nil { return nil, fmt.Errorf("error computing waiter delay, %w", err) } remainingTime -= delay // sleep for the delay amount before invoking a request if err := smithytime.SleepWithContext(ctx, delay); err != nil { return nil, fmt.Errorf("request cancelled while waiting, %w", err) } } return nil, fmt.Errorf("exceeded max wait time for StackCreateComplete waiter") } func stackCreateCompleteStateRetryable(ctx context.Context, input *DescribeStacksInput, output *DescribeStacksOutput, err error) (bool, error) { if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "CREATE_COMPLETE" var match = true listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } if len(listOfValues) == 0 { match = false } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) != expectedValue { match = false } } if match { return false, nil } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "CREATE_FAILED" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "DELETE_COMPLETE" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "DELETE_FAILED" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "ROLLBACK_FAILED" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "ROLLBACK_COMPLETE" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err != nil { var apiErr smithy.APIError ok := errors.As(err, &apiErr) if !ok { return false, fmt.Errorf("expected err to be of type smithy.APIError, got %w", err) } if "ValidationError" == apiErr.ErrorCode() { return false, fmt.Errorf("waiter state transitioned to Failure") } } return true, nil } // StackDeleteCompleteWaiterOptions are waiter options for // StackDeleteCompleteWaiter type StackDeleteCompleteWaiterOptions struct { // Set of options to modify how an operation is invoked. These apply to all // operations invoked for this client. Use functional options on operation call to // modify this list for per operation behavior. APIOptions []func(*middleware.Stack) error // MinDelay is the minimum amount of time to delay between retries. If unset, // StackDeleteCompleteWaiter will use default minimum delay of 30 seconds. Note // that MinDelay must resolve to a value lesser than or equal to the MaxDelay. MinDelay time.Duration // MaxDelay is the maximum amount of time to delay between retries. If unset or // set to zero, StackDeleteCompleteWaiter will use default max delay of 120 // seconds. Note that MaxDelay must resolve to value greater than or equal to the // MinDelay. MaxDelay time.Duration // LogWaitAttempts is used to enable logging for waiter retry attempts LogWaitAttempts bool // Retryable is function that can be used to override the service defined // waiter-behavior based on operation output, or returned error. This function is // used by the waiter to decide if a state is retryable or a terminal state. By // default service-modeled logic will populate this option. This option can thus be // used to define a custom waiter state with fall-back to service-modeled waiter // state mutators.The function returns an error in case of a failure state. In case // of retry state, this function returns a bool value of true and nil error, while // in case of success it returns a bool value of false and nil error. Retryable func(context.Context, *DescribeStacksInput, *DescribeStacksOutput, error) (bool, error) } // StackDeleteCompleteWaiter defines the waiters for StackDeleteComplete type StackDeleteCompleteWaiter struct { client DescribeStacksAPIClient options StackDeleteCompleteWaiterOptions } // NewStackDeleteCompleteWaiter constructs a StackDeleteCompleteWaiter. func NewStackDeleteCompleteWaiter(client DescribeStacksAPIClient, optFns ...func(*StackDeleteCompleteWaiterOptions)) *StackDeleteCompleteWaiter { options := StackDeleteCompleteWaiterOptions{} options.MinDelay = 30 * time.Second options.MaxDelay = 120 * time.Second options.Retryable = stackDeleteCompleteStateRetryable for _, fn := range optFns { fn(&options) } return &StackDeleteCompleteWaiter{ client: client, options: options, } } // Wait calls the waiter function for StackDeleteComplete waiter. The maxWaitDur // is the maximum wait duration the waiter will wait. The maxWaitDur is required // and must be greater than zero. func (w *StackDeleteCompleteWaiter) Wait(ctx context.Context, params *DescribeStacksInput, maxWaitDur time.Duration, optFns ...func(*StackDeleteCompleteWaiterOptions)) error { _, err := w.WaitForOutput(ctx, params, maxWaitDur, optFns...) return err } // WaitForOutput calls the waiter function for StackDeleteComplete waiter and // returns the output of the successful operation. The maxWaitDur is the maximum // wait duration the waiter will wait. The maxWaitDur is required and must be // greater than zero. func (w *StackDeleteCompleteWaiter) WaitForOutput(ctx context.Context, params *DescribeStacksInput, maxWaitDur time.Duration, optFns ...func(*StackDeleteCompleteWaiterOptions)) (*DescribeStacksOutput, error) { if maxWaitDur <= 0 { return nil, fmt.Errorf("maximum wait time for waiter must be greater than zero") } options := w.options for _, fn := range optFns { fn(&options) } if options.MaxDelay <= 0 { options.MaxDelay = 120 * time.Second } if options.MinDelay > options.MaxDelay { return nil, fmt.Errorf("minimum waiter delay %v must be lesser than or equal to maximum waiter delay of %v.", options.MinDelay, options.MaxDelay) } ctx, cancelFn := context.WithTimeout(ctx, maxWaitDur) defer cancelFn() logger := smithywaiter.Logger{} remainingTime := maxWaitDur var attempt int64 for { attempt++ apiOptions := options.APIOptions start := time.Now() if options.LogWaitAttempts { logger.Attempt = attempt apiOptions = append([]func(*middleware.Stack) error{}, options.APIOptions...) apiOptions = append(apiOptions, logger.AddLogger) } out, err := w.client.DescribeStacks(ctx, params, func(o *Options) { o.APIOptions = append(o.APIOptions, apiOptions...) }) retryable, err := options.Retryable(ctx, params, out, err) if err != nil { return nil, err } if !retryable { return out, nil } remainingTime -= time.Since(start) if remainingTime < options.MinDelay || remainingTime <= 0 { break } // compute exponential backoff between waiter retries delay, err := smithywaiter.ComputeDelay( attempt, options.MinDelay, options.MaxDelay, remainingTime, ) if err != nil { return nil, fmt.Errorf("error computing waiter delay, %w", err) } remainingTime -= delay // sleep for the delay amount before invoking a request if err := smithytime.SleepWithContext(ctx, delay); err != nil { return nil, fmt.Errorf("request cancelled while waiting, %w", err) } } return nil, fmt.Errorf("exceeded max wait time for StackDeleteComplete waiter") } func stackDeleteCompleteStateRetryable(ctx context.Context, input *DescribeStacksInput, output *DescribeStacksOutput, err error) (bool, error) { if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "DELETE_COMPLETE" var match = true listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } if len(listOfValues) == 0 { match = false } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) != expectedValue { match = false } } if match { return false, nil } } if err != nil { var apiErr smithy.APIError ok := errors.As(err, &apiErr) if !ok { return false, fmt.Errorf("expected err to be of type smithy.APIError, got %w", err) } if "ValidationError" == apiErr.ErrorCode() { return false, nil } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "DELETE_FAILED" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "CREATE_FAILED" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "ROLLBACK_FAILED" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "UPDATE_ROLLBACK_IN_PROGRESS" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "UPDATE_ROLLBACK_FAILED" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "UPDATE_ROLLBACK_COMPLETE" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "UPDATE_COMPLETE" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } return true, nil } // StackExistsWaiterOptions are waiter options for StackExistsWaiter type StackExistsWaiterOptions struct { // Set of options to modify how an operation is invoked. These apply to all // operations invoked for this client. Use functional options on operation call to // modify this list for per operation behavior. APIOptions []func(*middleware.Stack) error // MinDelay is the minimum amount of time to delay between retries. If unset, // StackExistsWaiter will use default minimum delay of 5 seconds. Note that // MinDelay must resolve to a value lesser than or equal to the MaxDelay. MinDelay time.Duration // MaxDelay is the maximum amount of time to delay between retries. If unset or // set to zero, StackExistsWaiter will use default max delay of 120 seconds. Note // that MaxDelay must resolve to value greater than or equal to the MinDelay. MaxDelay time.Duration // LogWaitAttempts is used to enable logging for waiter retry attempts LogWaitAttempts bool // Retryable is function that can be used to override the service defined // waiter-behavior based on operation output, or returned error. This function is // used by the waiter to decide if a state is retryable or a terminal state. By // default service-modeled logic will populate this option. This option can thus be // used to define a custom waiter state with fall-back to service-modeled waiter // state mutators.The function returns an error in case of a failure state. In case // of retry state, this function returns a bool value of true and nil error, while // in case of success it returns a bool value of false and nil error. Retryable func(context.Context, *DescribeStacksInput, *DescribeStacksOutput, error) (bool, error) } // StackExistsWaiter defines the waiters for StackExists type StackExistsWaiter struct { client DescribeStacksAPIClient options StackExistsWaiterOptions } // NewStackExistsWaiter constructs a StackExistsWaiter. func NewStackExistsWaiter(client DescribeStacksAPIClient, optFns ...func(*StackExistsWaiterOptions)) *StackExistsWaiter { options := StackExistsWaiterOptions{} options.MinDelay = 5 * time.Second options.MaxDelay = 120 * time.Second options.Retryable = stackExistsStateRetryable for _, fn := range optFns { fn(&options) } return &StackExistsWaiter{ client: client, options: options, } } // Wait calls the waiter function for StackExists waiter. The maxWaitDur is the // maximum wait duration the waiter will wait. The maxWaitDur is required and must // be greater than zero. func (w *StackExistsWaiter) Wait(ctx context.Context, params *DescribeStacksInput, maxWaitDur time.Duration, optFns ...func(*StackExistsWaiterOptions)) error { _, err := w.WaitForOutput(ctx, params, maxWaitDur, optFns...) return err } // WaitForOutput calls the waiter function for StackExists waiter and returns the // output of the successful operation. The maxWaitDur is the maximum wait duration // the waiter will wait. The maxWaitDur is required and must be greater than zero. func (w *StackExistsWaiter) WaitForOutput(ctx context.Context, params *DescribeStacksInput, maxWaitDur time.Duration, optFns ...func(*StackExistsWaiterOptions)) (*DescribeStacksOutput, error) { if maxWaitDur <= 0 { return nil, fmt.Errorf("maximum wait time for waiter must be greater than zero") } options := w.options for _, fn := range optFns { fn(&options) } if options.MaxDelay <= 0 { options.MaxDelay = 120 * time.Second } if options.MinDelay > options.MaxDelay { return nil, fmt.Errorf("minimum waiter delay %v must be lesser than or equal to maximum waiter delay of %v.", options.MinDelay, options.MaxDelay) } ctx, cancelFn := context.WithTimeout(ctx, maxWaitDur) defer cancelFn() logger := smithywaiter.Logger{} remainingTime := maxWaitDur var attempt int64 for { attempt++ apiOptions := options.APIOptions start := time.Now() if options.LogWaitAttempts { logger.Attempt = attempt apiOptions = append([]func(*middleware.Stack) error{}, options.APIOptions...) apiOptions = append(apiOptions, logger.AddLogger) } out, err := w.client.DescribeStacks(ctx, params, func(o *Options) { o.APIOptions = append(o.APIOptions, apiOptions...) }) retryable, err := options.Retryable(ctx, params, out, err) if err != nil { return nil, err } if !retryable { return out, nil } remainingTime -= time.Since(start) if remainingTime < options.MinDelay || remainingTime <= 0 { break } // compute exponential backoff between waiter retries delay, err := smithywaiter.ComputeDelay( attempt, options.MinDelay, options.MaxDelay, remainingTime, ) if err != nil { return nil, fmt.Errorf("error computing waiter delay, %w", err) } remainingTime -= delay // sleep for the delay amount before invoking a request if err := smithytime.SleepWithContext(ctx, delay); err != nil { return nil, fmt.Errorf("request cancelled while waiting, %w", err) } } return nil, fmt.Errorf("exceeded max wait time for StackExists waiter") } func stackExistsStateRetryable(ctx context.Context, input *DescribeStacksInput, output *DescribeStacksOutput, err error) (bool, error) { if err == nil { return false, nil } if err != nil { var apiErr smithy.APIError ok := errors.As(err, &apiErr) if !ok { return false, fmt.Errorf("expected err to be of type smithy.APIError, got %w", err) } if "ValidationError" == apiErr.ErrorCode() { return true, nil } } return true, nil } // StackImportCompleteWaiterOptions are waiter options for // StackImportCompleteWaiter type StackImportCompleteWaiterOptions struct { // Set of options to modify how an operation is invoked. These apply to all // operations invoked for this client. Use functional options on operation call to // modify this list for per operation behavior. APIOptions []func(*middleware.Stack) error // MinDelay is the minimum amount of time to delay between retries. If unset, // StackImportCompleteWaiter will use default minimum delay of 30 seconds. Note // that MinDelay must resolve to a value lesser than or equal to the MaxDelay. MinDelay time.Duration // MaxDelay is the maximum amount of time to delay between retries. If unset or // set to zero, StackImportCompleteWaiter will use default max delay of 120 // seconds. Note that MaxDelay must resolve to value greater than or equal to the // MinDelay. MaxDelay time.Duration // LogWaitAttempts is used to enable logging for waiter retry attempts LogWaitAttempts bool // Retryable is function that can be used to override the service defined // waiter-behavior based on operation output, or returned error. This function is // used by the waiter to decide if a state is retryable or a terminal state. By // default service-modeled logic will populate this option. This option can thus be // used to define a custom waiter state with fall-back to service-modeled waiter // state mutators.The function returns an error in case of a failure state. In case // of retry state, this function returns a bool value of true and nil error, while // in case of success it returns a bool value of false and nil error. Retryable func(context.Context, *DescribeStacksInput, *DescribeStacksOutput, error) (bool, error) } // StackImportCompleteWaiter defines the waiters for StackImportComplete type StackImportCompleteWaiter struct { client DescribeStacksAPIClient options StackImportCompleteWaiterOptions } // NewStackImportCompleteWaiter constructs a StackImportCompleteWaiter. func NewStackImportCompleteWaiter(client DescribeStacksAPIClient, optFns ...func(*StackImportCompleteWaiterOptions)) *StackImportCompleteWaiter { options := StackImportCompleteWaiterOptions{} options.MinDelay = 30 * time.Second options.MaxDelay = 120 * time.Second options.Retryable = stackImportCompleteStateRetryable for _, fn := range optFns { fn(&options) } return &StackImportCompleteWaiter{ client: client, options: options, } } // Wait calls the waiter function for StackImportComplete waiter. The maxWaitDur // is the maximum wait duration the waiter will wait. The maxWaitDur is required // and must be greater than zero. func (w *StackImportCompleteWaiter) Wait(ctx context.Context, params *DescribeStacksInput, maxWaitDur time.Duration, optFns ...func(*StackImportCompleteWaiterOptions)) error { _, err := w.WaitForOutput(ctx, params, maxWaitDur, optFns...) return err } // WaitForOutput calls the waiter function for StackImportComplete waiter and // returns the output of the successful operation. The maxWaitDur is the maximum // wait duration the waiter will wait. The maxWaitDur is required and must be // greater than zero. func (w *StackImportCompleteWaiter) WaitForOutput(ctx context.Context, params *DescribeStacksInput, maxWaitDur time.Duration, optFns ...func(*StackImportCompleteWaiterOptions)) (*DescribeStacksOutput, error) { if maxWaitDur <= 0 { return nil, fmt.Errorf("maximum wait time for waiter must be greater than zero") } options := w.options for _, fn := range optFns { fn(&options) } if options.MaxDelay <= 0 { options.MaxDelay = 120 * time.Second } if options.MinDelay > options.MaxDelay { return nil, fmt.Errorf("minimum waiter delay %v must be lesser than or equal to maximum waiter delay of %v.", options.MinDelay, options.MaxDelay) } ctx, cancelFn := context.WithTimeout(ctx, maxWaitDur) defer cancelFn() logger := smithywaiter.Logger{} remainingTime := maxWaitDur var attempt int64 for { attempt++ apiOptions := options.APIOptions start := time.Now() if options.LogWaitAttempts { logger.Attempt = attempt apiOptions = append([]func(*middleware.Stack) error{}, options.APIOptions...) apiOptions = append(apiOptions, logger.AddLogger) } out, err := w.client.DescribeStacks(ctx, params, func(o *Options) { o.APIOptions = append(o.APIOptions, apiOptions...) }) retryable, err := options.Retryable(ctx, params, out, err) if err != nil { return nil, err } if !retryable { return out, nil } remainingTime -= time.Since(start) if remainingTime < options.MinDelay || remainingTime <= 0 { break } // compute exponential backoff between waiter retries delay, err := smithywaiter.ComputeDelay( attempt, options.MinDelay, options.MaxDelay, remainingTime, ) if err != nil { return nil, fmt.Errorf("error computing waiter delay, %w", err) } remainingTime -= delay // sleep for the delay amount before invoking a request if err := smithytime.SleepWithContext(ctx, delay); err != nil { return nil, fmt.Errorf("request cancelled while waiting, %w", err) } } return nil, fmt.Errorf("exceeded max wait time for StackImportComplete waiter") } func stackImportCompleteStateRetryable(ctx context.Context, input *DescribeStacksInput, output *DescribeStacksOutput, err error) (bool, error) { if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "IMPORT_COMPLETE" var match = true listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } if len(listOfValues) == 0 { match = false } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) != expectedValue { match = false } } if match { return false, nil } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "ROLLBACK_COMPLETE" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "ROLLBACK_FAILED" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "IMPORT_ROLLBACK_IN_PROGRESS" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "IMPORT_ROLLBACK_FAILED" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "IMPORT_ROLLBACK_COMPLETE" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err != nil { var apiErr smithy.APIError ok := errors.As(err, &apiErr) if !ok { return false, fmt.Errorf("expected err to be of type smithy.APIError, got %w", err) } if "ValidationError" == apiErr.ErrorCode() { return false, fmt.Errorf("waiter state transitioned to Failure") } } return true, nil } // StackRollbackCompleteWaiterOptions are waiter options for // StackRollbackCompleteWaiter type StackRollbackCompleteWaiterOptions struct { // Set of options to modify how an operation is invoked. These apply to all // operations invoked for this client. Use functional options on operation call to // modify this list for per operation behavior. APIOptions []func(*middleware.Stack) error // MinDelay is the minimum amount of time to delay between retries. If unset, // StackRollbackCompleteWaiter will use default minimum delay of 30 seconds. Note // that MinDelay must resolve to a value lesser than or equal to the MaxDelay. MinDelay time.Duration // MaxDelay is the maximum amount of time to delay between retries. If unset or // set to zero, StackRollbackCompleteWaiter will use default max delay of 120 // seconds. Note that MaxDelay must resolve to value greater than or equal to the // MinDelay. MaxDelay time.Duration // LogWaitAttempts is used to enable logging for waiter retry attempts LogWaitAttempts bool // Retryable is function that can be used to override the service defined // waiter-behavior based on operation output, or returned error. This function is // used by the waiter to decide if a state is retryable or a terminal state. By // default service-modeled logic will populate this option. This option can thus be // used to define a custom waiter state with fall-back to service-modeled waiter // state mutators.The function returns an error in case of a failure state. In case // of retry state, this function returns a bool value of true and nil error, while // in case of success it returns a bool value of false and nil error. Retryable func(context.Context, *DescribeStacksInput, *DescribeStacksOutput, error) (bool, error) } // StackRollbackCompleteWaiter defines the waiters for StackRollbackComplete type StackRollbackCompleteWaiter struct { client DescribeStacksAPIClient options StackRollbackCompleteWaiterOptions } // NewStackRollbackCompleteWaiter constructs a StackRollbackCompleteWaiter. func NewStackRollbackCompleteWaiter(client DescribeStacksAPIClient, optFns ...func(*StackRollbackCompleteWaiterOptions)) *StackRollbackCompleteWaiter { options := StackRollbackCompleteWaiterOptions{} options.MinDelay = 30 * time.Second options.MaxDelay = 120 * time.Second options.Retryable = stackRollbackCompleteStateRetryable for _, fn := range optFns { fn(&options) } return &StackRollbackCompleteWaiter{ client: client, options: options, } } // Wait calls the waiter function for StackRollbackComplete waiter. The maxWaitDur // is the maximum wait duration the waiter will wait. The maxWaitDur is required // and must be greater than zero. func (w *StackRollbackCompleteWaiter) Wait(ctx context.Context, params *DescribeStacksInput, maxWaitDur time.Duration, optFns ...func(*StackRollbackCompleteWaiterOptions)) error { _, err := w.WaitForOutput(ctx, params, maxWaitDur, optFns...) return err } // WaitForOutput calls the waiter function for StackRollbackComplete waiter and // returns the output of the successful operation. The maxWaitDur is the maximum // wait duration the waiter will wait. The maxWaitDur is required and must be // greater than zero. func (w *StackRollbackCompleteWaiter) WaitForOutput(ctx context.Context, params *DescribeStacksInput, maxWaitDur time.Duration, optFns ...func(*StackRollbackCompleteWaiterOptions)) (*DescribeStacksOutput, error) { if maxWaitDur <= 0 { return nil, fmt.Errorf("maximum wait time for waiter must be greater than zero") } options := w.options for _, fn := range optFns { fn(&options) } if options.MaxDelay <= 0 { options.MaxDelay = 120 * time.Second } if options.MinDelay > options.MaxDelay { return nil, fmt.Errorf("minimum waiter delay %v must be lesser than or equal to maximum waiter delay of %v.", options.MinDelay, options.MaxDelay) } ctx, cancelFn := context.WithTimeout(ctx, maxWaitDur) defer cancelFn() logger := smithywaiter.Logger{} remainingTime := maxWaitDur var attempt int64 for { attempt++ apiOptions := options.APIOptions start := time.Now() if options.LogWaitAttempts { logger.Attempt = attempt apiOptions = append([]func(*middleware.Stack) error{}, options.APIOptions...) apiOptions = append(apiOptions, logger.AddLogger) } out, err := w.client.DescribeStacks(ctx, params, func(o *Options) { o.APIOptions = append(o.APIOptions, apiOptions...) }) retryable, err := options.Retryable(ctx, params, out, err) if err != nil { return nil, err } if !retryable { return out, nil } remainingTime -= time.Since(start) if remainingTime < options.MinDelay || remainingTime <= 0 { break } // compute exponential backoff between waiter retries delay, err := smithywaiter.ComputeDelay( attempt, options.MinDelay, options.MaxDelay, remainingTime, ) if err != nil { return nil, fmt.Errorf("error computing waiter delay, %w", err) } remainingTime -= delay // sleep for the delay amount before invoking a request if err := smithytime.SleepWithContext(ctx, delay); err != nil { return nil, fmt.Errorf("request cancelled while waiting, %w", err) } } return nil, fmt.Errorf("exceeded max wait time for StackRollbackComplete waiter") } func stackRollbackCompleteStateRetryable(ctx context.Context, input *DescribeStacksInput, output *DescribeStacksOutput, err error) (bool, error) { if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "UPDATE_ROLLBACK_COMPLETE" var match = true listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } if len(listOfValues) == 0 { match = false } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) != expectedValue { match = false } } if match { return false, nil } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "UPDATE_FAILED" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "UPDATE_ROLLBACK_FAILED" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "DELETE_FAILED" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err != nil { var apiErr smithy.APIError ok := errors.As(err, &apiErr) if !ok { return false, fmt.Errorf("expected err to be of type smithy.APIError, got %w", err) } if "ValidationError" == apiErr.ErrorCode() { return false, fmt.Errorf("waiter state transitioned to Failure") } } return true, nil } // StackUpdateCompleteWaiterOptions are waiter options for // StackUpdateCompleteWaiter type StackUpdateCompleteWaiterOptions struct { // Set of options to modify how an operation is invoked. These apply to all // operations invoked for this client. Use functional options on operation call to // modify this list for per operation behavior. APIOptions []func(*middleware.Stack) error // MinDelay is the minimum amount of time to delay between retries. If unset, // StackUpdateCompleteWaiter will use default minimum delay of 30 seconds. Note // that MinDelay must resolve to a value lesser than or equal to the MaxDelay. MinDelay time.Duration // MaxDelay is the maximum amount of time to delay between retries. If unset or // set to zero, StackUpdateCompleteWaiter will use default max delay of 120 // seconds. Note that MaxDelay must resolve to value greater than or equal to the // MinDelay. MaxDelay time.Duration // LogWaitAttempts is used to enable logging for waiter retry attempts LogWaitAttempts bool // Retryable is function that can be used to override the service defined // waiter-behavior based on operation output, or returned error. This function is // used by the waiter to decide if a state is retryable or a terminal state. By // default service-modeled logic will populate this option. This option can thus be // used to define a custom waiter state with fall-back to service-modeled waiter // state mutators.The function returns an error in case of a failure state. In case // of retry state, this function returns a bool value of true and nil error, while // in case of success it returns a bool value of false and nil error. Retryable func(context.Context, *DescribeStacksInput, *DescribeStacksOutput, error) (bool, error) } // StackUpdateCompleteWaiter defines the waiters for StackUpdateComplete type StackUpdateCompleteWaiter struct { client DescribeStacksAPIClient options StackUpdateCompleteWaiterOptions } // NewStackUpdateCompleteWaiter constructs a StackUpdateCompleteWaiter. func NewStackUpdateCompleteWaiter(client DescribeStacksAPIClient, optFns ...func(*StackUpdateCompleteWaiterOptions)) *StackUpdateCompleteWaiter { options := StackUpdateCompleteWaiterOptions{} options.MinDelay = 30 * time.Second options.MaxDelay = 120 * time.Second options.Retryable = stackUpdateCompleteStateRetryable for _, fn := range optFns { fn(&options) } return &StackUpdateCompleteWaiter{ client: client, options: options, } } // Wait calls the waiter function for StackUpdateComplete waiter. The maxWaitDur // is the maximum wait duration the waiter will wait. The maxWaitDur is required // and must be greater than zero. func (w *StackUpdateCompleteWaiter) Wait(ctx context.Context, params *DescribeStacksInput, maxWaitDur time.Duration, optFns ...func(*StackUpdateCompleteWaiterOptions)) error { _, err := w.WaitForOutput(ctx, params, maxWaitDur, optFns...) return err } // WaitForOutput calls the waiter function for StackUpdateComplete waiter and // returns the output of the successful operation. The maxWaitDur is the maximum // wait duration the waiter will wait. The maxWaitDur is required and must be // greater than zero. func (w *StackUpdateCompleteWaiter) WaitForOutput(ctx context.Context, params *DescribeStacksInput, maxWaitDur time.Duration, optFns ...func(*StackUpdateCompleteWaiterOptions)) (*DescribeStacksOutput, error) { if maxWaitDur <= 0 { return nil, fmt.Errorf("maximum wait time for waiter must be greater than zero") } options := w.options for _, fn := range optFns { fn(&options) } if options.MaxDelay <= 0 { options.MaxDelay = 120 * time.Second } if options.MinDelay > options.MaxDelay { return nil, fmt.Errorf("minimum waiter delay %v must be lesser than or equal to maximum waiter delay of %v.", options.MinDelay, options.MaxDelay) } ctx, cancelFn := context.WithTimeout(ctx, maxWaitDur) defer cancelFn() logger := smithywaiter.Logger{} remainingTime := maxWaitDur var attempt int64 for { attempt++ apiOptions := options.APIOptions start := time.Now() if options.LogWaitAttempts { logger.Attempt = attempt apiOptions = append([]func(*middleware.Stack) error{}, options.APIOptions...) apiOptions = append(apiOptions, logger.AddLogger) } out, err := w.client.DescribeStacks(ctx, params, func(o *Options) { o.APIOptions = append(o.APIOptions, apiOptions...) }) retryable, err := options.Retryable(ctx, params, out, err) if err != nil { return nil, err } if !retryable { return out, nil } remainingTime -= time.Since(start) if remainingTime < options.MinDelay || remainingTime <= 0 { break } // compute exponential backoff between waiter retries delay, err := smithywaiter.ComputeDelay( attempt, options.MinDelay, options.MaxDelay, remainingTime, ) if err != nil { return nil, fmt.Errorf("error computing waiter delay, %w", err) } remainingTime -= delay // sleep for the delay amount before invoking a request if err := smithytime.SleepWithContext(ctx, delay); err != nil { return nil, fmt.Errorf("request cancelled while waiting, %w", err) } } return nil, fmt.Errorf("exceeded max wait time for StackUpdateComplete waiter") } func stackUpdateCompleteStateRetryable(ctx context.Context, input *DescribeStacksInput, output *DescribeStacksOutput, err error) (bool, error) { if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "UPDATE_COMPLETE" var match = true listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } if len(listOfValues) == 0 { match = false } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) != expectedValue { match = false } } if match { return false, nil } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "UPDATE_FAILED" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "UPDATE_ROLLBACK_FAILED" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err == nil { pathValue, err := jmespath.Search("Stacks[].StackStatus", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "UPDATE_ROLLBACK_COMPLETE" listOfValues, ok := pathValue.([]interface{}) if !ok { return false, fmt.Errorf("waiter comparator expected list got %T", pathValue) } for _, v := range listOfValues { value, ok := v.(types.StackStatus) if !ok { return false, fmt.Errorf("waiter comparator expected types.StackStatus value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } } if err != nil { var apiErr smithy.APIError ok := errors.As(err, &apiErr) if !ok { return false, fmt.Errorf("expected err to be of type smithy.APIError, got %w", err) } if "ValidationError" == apiErr.ErrorCode() { return false, fmt.Errorf("waiter state transitioned to Failure") } } return true, nil } func newServiceMetadataMiddleware_opDescribeStacks(region string) *awsmiddleware.RegisterServiceMetadata { return &awsmiddleware.RegisterServiceMetadata{ Region: region, ServiceID: ServiceID, SigningName: "cloudformation", OperationName: "DescribeStacks", } }