Skip to content

Commit b2dfd7d

Browse files
committed
Moves waiter out of Retry to prevent multiple competing attempts to create stack instances
1 parent 5d060fe commit b2dfd7d

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

internal/service/cloudformation/stack_set_instance.go

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -279,41 +279,25 @@ func resourceStackSetInstanceCreate(ctx context.Context, d *schema.ResourceData,
279279
return create.AppendDiagError(diags, names.CloudFormation, create.ErrActionFlatteningResourceId, ResNameStackSetInstance, id, err)
280280
}
281281

282-
_, err = tfresource.RetryWhen(ctx, propagationTimeout,
283-
func() (interface{}, error) {
282+
output, err := tfresource.RetryGWhen(ctx, propagationTimeout,
283+
func() (*cloudformation.CreateStackInstancesOutput, error) {
284284
input.OperationId = aws.String(sdkid.UniqueId())
285285

286-
output, err := conn.CreateStackInstances(ctx, input)
287-
288-
if err != nil {
289-
return nil, err
290-
}
291-
292-
d.SetId(id)
293-
294-
operation, err := waitStackSetOperationSucceeded(ctx, conn, stackSetName, aws.ToString(output.OperationId), callAs, d.Timeout(schema.TimeoutCreate))
295-
296-
if err != nil {
297-
return nil, fmt.Errorf("waiting for create: %w", err)
298-
}
299-
300-
return operation, nil
286+
return conn.CreateStackInstances(ctx, input)
301287
},
302288
isRetryableIAMPropagationErr,
303-
304-
// IAM eventual consistency
305-
if strings.Contains(message, "The security token included in the request is invalid") {
306-
return true, err
307-
}
308-
309-
return false, err
310-
},
311289
)
312-
313290
if err != nil {
314291
return sdkdiag.AppendErrorf(diags, "creating CloudFormation StackSet (%s) Instance: %s", stackSetName, err)
315292
}
316293

294+
d.SetId(id)
295+
296+
_, err = waitStackSetOperationSucceeded(ctx, conn, stackSetName, aws.ToString(output.OperationId), callAs, d.Timeout(schema.TimeoutCreate))
297+
if err != nil {
298+
return sdkdiag.AppendErrorf(diags, "creating CloudFormation StackSet (%s) Instance: waiting for completion: %s", stackSetName, err)
299+
}
300+
317301
return append(diags, resourceStackSetInstanceRead(ctx, d, meta)...)
318302
}
319303

0 commit comments

Comments
 (0)