Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/budgets_budget_action - new resource #19554

Merged
merged 10 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -532,6 +532,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