diff --git a/.changelog/31097.txt b/.changelog/31097.txt new file mode 100644 index 000000000000..1593f3fada80 --- /dev/null +++ b/.changelog/31097.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_sfn_state_machine: Add configurable timeouts +``` \ No newline at end of file diff --git a/internal/service/sfn/state_machine.go b/internal/service/sfn/state_machine.go index bf28d7e32f4b..bc16ec8068f6 100644 --- a/internal/service/sfn/state_machine.go +++ b/internal/service/sfn/state_machine.go @@ -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, @@ -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") @@ -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 { @@ -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) } @@ -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) diff --git a/website/docs/r/sfn_state_machine.html.markdown b/website/docs/r/sfn_state_machine.html.markdown index 2969fa833058..ca4d0c0722e3 100644 --- a/website/docs/r/sfn_state_machine.html.markdown +++ b/website/docs/r/sfn_state_machine.html.markdown @@ -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.,