From 45c021e34f8f7e484aac2675018cd1eaab4af372 Mon Sep 17 00:00:00 2001 From: Anthony Wat Date: Thu, 23 Jan 2025 20:29:59 -0500 Subject: [PATCH] feat: Add configurable timeouts to aws_organizations_account --- .changelog/41059.txt | 3 +++ internal/service/organizations/account.go | 17 +++++++++++------ .../docs/r/organizations_account.html.markdown | 7 +++++++ 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 .changelog/41059.txt diff --git a/.changelog/41059.txt b/.changelog/41059.txt new file mode 100644 index 00000000000..5cae27a7326 --- /dev/null +++ b/.changelog/41059.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_organizations_account: Add configurable timeouts for Create and Delete +``` \ No newline at end of file diff --git a/internal/service/organizations/account.go b/internal/service/organizations/account.go index bad296485ce..4ca436e0d8a 100644 --- a/internal/service/organizations/account.go +++ b/internal/service/organizations/account.go @@ -42,6 +42,11 @@ func resourceAccount() *schema.Resource { StateContext: resourceAccountImportState, }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(10 * time.Minute), + Delete: schema.DefaultTimeout(10 * time.Minute), + }, + Schema: map[string]*schema.Schema{ names.AttrARN: { Type: schema.TypeString, @@ -173,7 +178,7 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, meta int status = outputRaw.(*organizations.CreateAccountOutput).CreateAccountStatus } - output, err := waitAccountCreated(ctx, conn, aws.ToString(status.Id)) + output, err := waitAccountCreated(ctx, conn, aws.ToString(status.Id), d.Timeout(schema.TimeoutCreate)) if err != nil { return sdkdiag.AppendErrorf(diags, "waiting for AWS Organizations Account (%s) create: %s", d.Get(names.AttrName).(string), err) @@ -291,7 +296,7 @@ func resourceAccountDelete(ctx context.Context, d *schema.ResourceData, meta int } if close { - if _, err := waitAccountDeleted(ctx, conn, d.Id()); err != nil { + if _, err := waitAccountDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for AWS Organizations Account (%s) delete: %s", d.Id(), err) } } @@ -431,13 +436,13 @@ func statusCreateAccountState(ctx context.Context, conn *organizations.Client, i } } -func waitAccountCreated(ctx context.Context, conn *organizations.Client, id string) (*awstypes.CreateAccountStatus, error) { +func waitAccountCreated(ctx context.Context, conn *organizations.Client, id string, timeout time.Duration) (*awstypes.CreateAccountStatus, error) { stateConf := &retry.StateChangeConf{ Pending: enum.Slice(awstypes.CreateAccountStateInProgress), Target: enum.Slice(awstypes.CreateAccountStateSucceeded), Refresh: statusCreateAccountState(ctx, conn, id), PollInterval: 10 * time.Second, - Timeout: 5 * time.Minute, + Timeout: timeout, } outputRaw, err := stateConf.WaitForStateContext(ctx) @@ -469,13 +474,13 @@ func statusAccountStatus(ctx context.Context, conn *organizations.Client, id str } } -func waitAccountDeleted(ctx context.Context, conn *organizations.Client, id string) (*awstypes.Account, error) { +func waitAccountDeleted(ctx context.Context, conn *organizations.Client, id string, timeout time.Duration) (*awstypes.Account, error) { stateConf := &retry.StateChangeConf{ Pending: enum.Slice(awstypes.AccountStatusPendingClosure, awstypes.AccountStatusActive), Target: []string{}, Refresh: statusAccountStatus(ctx, conn, id), PollInterval: 10 * time.Second, - Timeout: 5 * time.Minute, + Timeout: timeout, } outputRaw, err := stateConf.WaitForStateContext(ctx) diff --git a/website/docs/r/organizations_account.html.markdown b/website/docs/r/organizations_account.html.markdown index 0bf0dab6339..efb2a5b6064 100644 --- a/website/docs/r/organizations_account.html.markdown +++ b/website/docs/r/organizations_account.html.markdown @@ -49,6 +49,13 @@ This resource exports the following attributes in addition to the arguments abov * `status` - The status of the account in the organization. * `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 `10m`) +- `delete` - (Default `10m`) + ## Import In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import the AWS member account using the `account_id`. For example: