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

Added tags to budgets resources #37361

Merged
merged 10 commits into from
May 10, 2024
9 changes: 9 additions & 0 deletions .changelog/37361.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```release-note:enhancement
resource/aws_budgets_budget: Add `tags` argument
```
```release-note:enhancement
resource/aws_budgets_budget_action: Add `tags` argument
```
```release-note:enhancement
data-source/aws_budgets_budget: Add `tags` attribute
```
10 changes: 8 additions & 2 deletions internal/service/budgets/budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
"github.com/hashicorp/terraform-provider-aws/names"
"github.com/shopspring/decimal"
)

// @SDKResource("aws_budgets_budget")
// @Tags(identifierAttribute="arn")
func ResourceBudget() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceBudgetCreate,
Expand Down Expand Up @@ -272,6 +274,8 @@ func ResourceBudget() *schema.Resource {
},
ConflictsWith: []string{"limit_amount", "limit_unit"},
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
"time_period_end": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -290,6 +294,7 @@ func ResourceBudget() *schema.Resource {
ValidateDiagFunc: enum.Validate[awstypes.TimeUnit](),
},
},
CustomizeDiff: verify.SetTagsDiff,
}
}

Expand All @@ -313,8 +318,9 @@ func resourceBudgetCreate(ctx context.Context, d *schema.ResourceData, meta inte
}

_, err = conn.CreateBudget(ctx, &budgets.CreateBudgetInput{
AccountId: aws.String(accountID),
Budget: budget,
AccountId: aws.String(accountID),
Budget: budget,
ResourceTags: getTagsIn(ctx),
})

if err != nil {
Expand Down
60 changes: 34 additions & 26 deletions internal/service/budgets/budget_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
"github.com/hashicorp/terraform-provider-aws/names"
)

// @SDKResource("aws_budgets_budget_action")
// @Tags(identifierAttribute="arn")
func ResourceBudgetAction() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceBudgetActionCreate,
Expand Down Expand Up @@ -221,7 +223,10 @@ func ResourceBudgetAction() *schema.Resource {
},
},
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
},
CustomizeDiff: verify.SetTagsDiff,
}
}

Expand All @@ -243,6 +248,7 @@ func resourceBudgetActionCreate(ctx context.Context, d *schema.ResourceData, met
ExecutionRoleArn: aws.String(d.Get("execution_role_arn").(string)),
NotificationType: awstypes.NotificationType(d.Get("notification_type").(string)),
Subscribers: expandBudgetActionSubscriber(d.Get("subscriber").(*schema.Set)),
ResourceTags: getTagsIn(ctx),
}

outputRaw, err := tfresource.RetryWhenIsA[*awstypes.AccessDeniedException](ctx, propagationTimeout, func() (interface{}, error) {
Expand Down Expand Up @@ -324,40 +330,42 @@ func resourceBudgetActionUpdate(ctx context.Context, d *schema.ResourceData, met
return sdkdiag.AppendFromErr(diags, err)
}

input := &budgets.UpdateBudgetActionInput{
AccountId: aws.String(accountID),
ActionId: aws.String(actionID),
BudgetName: aws.String(budgetName),
}
if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) {
input := &budgets.UpdateBudgetActionInput{
AccountId: aws.String(accountID),
ActionId: aws.String(actionID),
BudgetName: aws.String(budgetName),
}

if d.HasChange("action_threshold") {
input.ActionThreshold = expandBudgetActionActionThreshold(d.Get("action_threshold").([]interface{}))
}
if d.HasChange("action_threshold") {
input.ActionThreshold = expandBudgetActionActionThreshold(d.Get("action_threshold").([]interface{}))
}

if d.HasChange("approval_model") {
input.ApprovalModel = awstypes.ApprovalModel(d.Get("approval_model").(string))
}
if d.HasChange("approval_model") {
input.ApprovalModel = awstypes.ApprovalModel(d.Get("approval_model").(string))
}

if d.HasChange("definition") {
input.Definition = expandBudgetActionActionDefinition(d.Get("definition").([]interface{}))
}
if d.HasChange("definition") {
input.Definition = expandBudgetActionActionDefinition(d.Get("definition").([]interface{}))
}

if d.HasChange("execution_role_arn") {
input.ExecutionRoleArn = aws.String(d.Get("execution_role_arn").(string))
}
if d.HasChange("execution_role_arn") {
input.ExecutionRoleArn = aws.String(d.Get("execution_role_arn").(string))
}

if d.HasChange("notification_type") {
input.NotificationType = awstypes.NotificationType(d.Get("notification_type").(string))
}
if d.HasChange("notification_type") {
input.NotificationType = awstypes.NotificationType(d.Get("notification_type").(string))
}

if d.HasChange("subscriber") {
input.Subscribers = expandBudgetActionSubscriber(d.Get("subscriber").(*schema.Set))
}
if d.HasChange("subscriber") {
input.Subscribers = expandBudgetActionSubscriber(d.Get("subscriber").(*schema.Set))
}

_, err = conn.UpdateBudgetAction(ctx, input)
_, err = conn.UpdateBudgetAction(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "updating Budget Action (%s): %s", d.Id(), err)
if err != nil {
return sdkdiag.AppendErrorf(diags, "updating Budget Action (%s): %s", d.Id(), err)
}
}

return append(diags, resourceBudgetActionRead(ctx, d, meta)...)
Expand Down
Loading
Loading