Skip to content

Commit

Permalink
Merge pull request #19554 from DrFaust92/r/budget_action
Browse files Browse the repository at this point in the history
r/budgets_budget_action - new resource
  • Loading branch information
ewbankkit authored Jun 14, 2021
2 parents 176f8d2 + 4f0153d commit 5785cf6
Show file tree
Hide file tree
Showing 9 changed files with 1,137 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/19554.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_budgets_budget_action
```
27 changes: 27 additions & 0 deletions aws/internal/service/budgets/finder/finder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package finder

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/budgets"
tfbudgets "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/budgets"
)

func ActionById(conn *budgets.Budgets, id string) (*budgets.DescribeBudgetActionOutput, error) {
accountID, actionID, budgetName, err := tfbudgets.DecodeBudgetsBudgetActionID(id)
if err != nil {
return nil, err
}

input := &budgets.DescribeBudgetActionInput{
BudgetName: aws.String(budgetName),
AccountId: aws.String(accountID),
ActionId: aws.String(actionID),
}

out, err := conn.DescribeBudgetAction(input)
if err != nil {
return nil, err
}

return out, nil
}
14 changes: 14 additions & 0 deletions aws/internal/service/budgets/id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package glue

import (
"fmt"
"strings"
)

func DecodeBudgetsBudgetActionID(id string) (string, string, string, error) {
parts := strings.Split(id, ":")
if len(parts) != 3 {
return "", "", "", fmt.Errorf("Unexpected format of ID (%q), expected AccountID:ActionID:BudgetName", id)
}
return parts[0], parts[1], parts[2], nil
}
24 changes: 24 additions & 0 deletions aws/internal/service/budgets/waiter/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package waiter

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/budgets"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/budgets/finder"
)

func ActionStatus(conn *budgets.Budgets, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
out, err := finder.ActionById(conn, id)
if err != nil {
if tfawserr.ErrCodeEquals(err, budgets.ErrCodeNotFoundException) {
return nil, "", nil
}
return nil, "", err
}

action := out.Action
return action, aws.StringValue(action.Status), err
}
}
36 changes: 36 additions & 0 deletions aws/internal/service/budgets/waiter/waiter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package waiter

import (
"time"

"github.com/aws/aws-sdk-go/service/budgets"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

const (
ActionAvailableTimeout = 2 * time.Minute
)

func ActionAvailable(conn *budgets.Budgets, id string) (*budgets.Action, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{
budgets.ActionStatusExecutionInProgress,
budgets.ActionStatusStandby,
},
Target: []string{
budgets.ActionStatusExecutionSuccess,
budgets.ActionStatusExecutionFailure,
budgets.ActionStatusPending,
},
Refresh: ActionStatus(conn, id),
Timeout: ActionAvailableTimeout,
}

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*budgets.Action); ok {
return v, err
}

return nil, err
}
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ func Provider() *schema.Provider {
"aws_backup_vault_notifications": resourceAwsBackupVaultNotifications(),
"aws_backup_vault_policy": resourceAwsBackupVaultPolicy(),
"aws_budgets_budget": resourceAwsBudgetsBudget(),
"aws_budgets_budget_action": resourceAwsBudgetsBudgetAction(),
"aws_cloud9_environment_ec2": resourceAwsCloud9EnvironmentEc2(),
"aws_cloudformation_stack": resourceAwsCloudFormationStack(),
"aws_cloudformation_stack_set": resourceAwsCloudFormationStackSet(),
Expand Down
Loading

0 comments on commit 5785cf6

Please sign in to comment.