Skip to content

Commit

Permalink
Merge pull request #29976 from hashicorp/b-configurable-timeouts
Browse files Browse the repository at this point in the history
Extend timeouts for aws_budget_actions
  • Loading branch information
nam054 authored Mar 16, 2023
2 parents 11d3319 + be814c7 commit 18c6814
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .changelog/29976.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_budgets_action: Extend and add configurable timeouts for create and update
```
17 changes: 9 additions & 8 deletions internal/service/budgets/budget_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func ResourceBudgetAction() *schema.Resource {
StateContext: schema.ImportStatePassthroughContext,
},

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

Schema: map[string]*schema.Schema{
"account_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -245,7 +250,7 @@ func resourceBudgetActionCreate(ctx context.Context, d *schema.ResourceData, met

d.SetId(BudgetActionCreateResourceID(accountID, actionID, budgetName))

if _, err := waitActionAvailable(ctx, conn, accountID, actionID, budgetName); err != nil {
if _, err := waitActionAvailable(ctx, conn, accountID, actionID, budgetName, d.Timeout(schema.TimeoutCreate)); err != nil {
return diag.Errorf("waiting for Budget Action (%s) create: %s", d.Id(), err)
}

Expand Down Expand Up @@ -346,7 +351,7 @@ func resourceBudgetActionUpdate(ctx context.Context, d *schema.ResourceData, met
return diag.Errorf("updating Budget Action (%s): %s", d.Id(), err)
}

if _, err := waitActionAvailable(ctx, conn, accountID, actionID, budgetName); err != nil {
if _, err := waitActionAvailable(ctx, conn, accountID, actionID, budgetName, d.Timeout(schema.TimeoutUpdate)); err != nil {
return diag.Errorf("waiting for Budget Action (%s) update: %s", d.Id(), err)
}

Expand Down Expand Up @@ -446,11 +451,7 @@ func statusAction(ctx context.Context, conn *budgets.Budgets, accountID, actionI
}
}

const (
actionAvailableTimeout = 2 * time.Minute
)

func waitActionAvailable(ctx context.Context, conn *budgets.Budgets, accountID, actionID, budgetName string) (*budgets.Action, error) { //nolint:unparam
func waitActionAvailable(ctx context.Context, conn *budgets.Budgets, accountID, actionID, budgetName string, timeout time.Duration) (*budgets.Action, error) { //nolint:unparam
stateConf := &resource.StateChangeConf{
Pending: []string{
budgets.ActionStatusExecutionInProgress,
Expand All @@ -462,7 +463,7 @@ func waitActionAvailable(ctx context.Context, conn *budgets.Budgets, accountID,
budgets.ActionStatusPending,
},
Refresh: statusAction(ctx, conn, accountID, actionID, budgetName),
Timeout: actionAvailableTimeout,
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/budgets_budget_action.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ In addition to all arguments above, the following attributes are exported:
* `arn` - The ARN of the budget action.
* `status` - The status of the budget action.

## Timeouts

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

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

## Import

Budgets can be imported using `AccountID:ActionID:BudgetName`, e.g.,
Expand Down

0 comments on commit 18c6814

Please sign in to comment.