Skip to content

Commit

Permalink
feat: Add configurable timeouts to aws_organizations_account
Browse files Browse the repository at this point in the history
  • Loading branch information
acwwat committed Jan 24, 2025
1 parent 169b319 commit 087fbe7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
17 changes: 11 additions & 6 deletions internal/service/organizations/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/organizations_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 087fbe7

Please sign in to comment.