-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19554 from DrFaust92/r/budget_action
r/budgets_budget_action - new resource
- Loading branch information
Showing
9 changed files
with
1,137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-resource | ||
aws_budgets_budget_action | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.