Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/31097.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_sfn_state_machine: Add configurable timeouts
```
22 changes: 11 additions & 11 deletions internal/service/sfn/state_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func ResourceStateMachine() *schema.Resource {
StateContext: schema.ImportStatePassthroughContext,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(5 * time.Minute),
Update: schema.DefaultTimeout(1 * time.Minute),
Delete: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Expand Down Expand Up @@ -159,7 +165,7 @@ func resourceStateMachineCreate(ctx context.Context, d *schema.ResourceData, met
// Note: the instance may be in a deleting mode, hence the retry
// when creating the step function. This can happen when we are
// updating the resource (since there is no update API call).
outputRaw, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, stateMachineCreatedTimeout, func() (interface{}, error) {
outputRaw, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, d.Timeout(schema.TimeoutCreate), func() (interface{}, error) {
return conn.CreateStateMachineWithContext(ctx, input)
}, sfn.ErrCodeStateMachineDeleting, "AccessDeniedException")

Expand Down Expand Up @@ -247,7 +253,7 @@ func resourceStateMachineUpdate(ctx context.Context, d *schema.ResourceData, met
}

// Handle eventual consistency after update.
err = retry.RetryContext(ctx, stateMachineUpdatedTimeout, func() *retry.RetryError { // nosemgrep:ci.helper-schema-retry-RetryContext-without-TimeoutError-check
err = retry.RetryContext(ctx, d.Timeout(schema.TimeoutUpdate), func() *retry.RetryError { // nosemgrep:ci.helper-schema-retry-RetryContext-without-TimeoutError-check
output, err := FindStateMachineByARN(ctx, conn, d.Id())

if err != nil {
Expand Down Expand Up @@ -285,7 +291,7 @@ func resourceStateMachineDelete(ctx context.Context, d *schema.ResourceData, met
return diag.Errorf("deleting Step Functions State Machine (%s): %s", d.Id(), err)
}

if _, err := waitStateMachineDeleted(ctx, conn, d.Id()); err != nil {
if _, err := waitStateMachineDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil {
return diag.Errorf("waiting for Step Functions State Machine (%s) delete: %s", d.Id(), err)
}

Expand Down Expand Up @@ -333,18 +339,12 @@ func statusStateMachine(ctx context.Context, conn *sfn.SFN, stateMachineArn stri
}
}

const (
stateMachineCreatedTimeout = 5 * time.Minute
stateMachineDeletedTimeout = 5 * time.Minute
stateMachineUpdatedTimeout = 1 * time.Minute
)

func waitStateMachineDeleted(ctx context.Context, conn *sfn.SFN, stateMachineArn string) (*sfn.DescribeStateMachineOutput, error) {
func waitStateMachineDeleted(ctx context.Context, conn *sfn.SFN, stateMachineArn string, timeout time.Duration) (*sfn.DescribeStateMachineOutput, error) {
stateConf := &retry.StateChangeConf{
Pending: []string{sfn.StateMachineStatusActive, sfn.StateMachineStatusDeleting},
Target: []string{},
Refresh: statusStateMachine(ctx, conn, stateMachineArn),
Timeout: stateMachineDeletedTimeout,
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/sfn_state_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ In addition to all arguments above, the following attributes are exported:
* `status` - The current status of the state machine. Either `ACTIVE` or `DELETING`.
* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block).

## Timeouts

[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts):

* `create` - (Default `5m`)
* `update` - (Default `1m`)
* `delete` - (Default `5m`)

## Import

State Machines can be imported using the `arn`, e.g.,
Expand Down