Skip to content

Commit a41a2d5

Browse files
committed
cloudformation/stack_set: Status and waiter
1 parent 161e9c4 commit a41a2d5

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

internal/service/cloudformation/status.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ func StatusChangeSet(ctx context.Context, conn *cloudformation.CloudFormation, s
2828
}
2929
}
3030

31+
func StatusStackSet(ctx context.Context, conn *cloudformation.CloudFormation, name, callAs string) retry.StateRefreshFunc {
32+
return func() (interface{}, string, error) {
33+
output, err := FindStackSetByName(ctx, conn, name, callAs)
34+
35+
if tfresource.NotFound(err) {
36+
return nil, "", nil
37+
}
38+
39+
if err != nil {
40+
return nil, "", err
41+
}
42+
43+
return output, aws.StringValue(output.Status), nil
44+
}
45+
}
46+
3147
func StatusStackSetOperation(ctx context.Context, conn *cloudformation.CloudFormation, stackSetName, operationID, callAs string) retry.StateRefreshFunc {
3248
return func() (interface{}, string, error) {
3349
output, err := FindStackSetOperationByStackSetNameAndOperationID(ctx, conn, stackSetName, operationID, callAs)

internal/service/cloudformation/wait.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ func WaitChangeSetCreated(ctx context.Context, conn *cloudformation.CloudFormati
4040
return nil, err
4141
}
4242

43+
func WaitStackSetCreated(ctx context.Context, conn *cloudformation.CloudFormation, name, callAs string, timeout time.Duration) (*cloudformation.StackSet, error) {
44+
stateConf := retry.StateChangeConf{
45+
Pending: []string{},
46+
Target: []string{cloudformation.StackSetStatusActive},
47+
Timeout: ChangeSetCreatedTimeout,
48+
Refresh: StatusStackSet(ctx, conn, name, callAs),
49+
Delay: 15 * time.Second,
50+
}
51+
52+
outputRaw, err := stateConf.WaitForStateContext(ctx)
53+
54+
if output, ok := outputRaw.(*cloudformation.StackSet); ok {
55+
if status := aws.StringValue(output.Status); status == cloudformation.ChangeSetStatusFailed {
56+
tfresource.SetLastError(err, fmt.Errorf("describing CloudFormation Stack Set (%s) results: %w", name, err))
57+
}
58+
59+
return output, err
60+
}
61+
62+
return nil, err
63+
}
64+
4365
const (
4466
stackSetOperationDelay = 5 * time.Second
4567
)

0 commit comments

Comments
 (0)