Skip to content

Commit

Permalink
Merge pull request #31395 from hashicorp/remove-aws_budgets_budget.co…
Browse files Browse the repository at this point in the history
…st_filters

r/aws_budgets_budget: Remove `cost_filters` attribute
  • Loading branch information
ewbankkit authored May 12, 2023
2 parents 26d3434 + f115142 commit 2f44386
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 59 deletions.
3 changes: 3 additions & 0 deletions .changelog/31395.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:breaking-change
resource/aws_budgets_budget: The `cost_filters` attribute has been removed
```
32 changes: 0 additions & 32 deletions internal/service/budgets/budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,6 @@ func ResourceBudget() *schema.Resource {
Required: true,
ValidateFunc: validation.StringInSlice(budgets.BudgetType_Values(), false),
},
"cost_filters": {
Type: schema.TypeMap,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
ConflictsWith: []string{"cost_filter"},
Deprecated: "Use the attribute \"cost_filter\" instead.",
},
"cost_filter": {
Type: schema.TypeSet,
Optional: true,
Expand All @@ -116,7 +108,6 @@ func ResourceBudget() *schema.Resource {
},
},
},
ConflictsWith: []string{"cost_filters"},
},
"cost_types": {
Type: schema.TypeList,
Expand Down Expand Up @@ -365,13 +356,9 @@ func resourceBudgetRead(ctx context.Context, d *schema.ResourceData, meta interf
d.Set("arn", arn.String())
d.Set("budget_type", budget.BudgetType)

// `cost_filters` should be removed in future releases
if err := d.Set("cost_filter", convertCostFiltersToMap(budget.CostFilters)); err != nil {
return diag.Errorf("setting cost_filter: %s", err)
}
if err := d.Set("cost_filters", convertCostFiltersToStringMap(budget.CostFilters)); err != nil {
return diag.Errorf("setting cost_filters: %s", err)
}
if err := d.Set("cost_types", flattenCostTypes(budget.CostTypes)); err != nil {
return diag.Errorf("setting cost_types: %s", err)
}
Expand Down Expand Up @@ -776,20 +763,6 @@ func convertCostFiltersToMap(costFilters map[string][]*string) []map[string]inte
return convertedCostFilters
}

func convertCostFiltersToStringMap(costFilters map[string][]*string) map[string]string {
convertedCostFilters := make(map[string]string)
for k, v := range costFilters {
filterValues := make([]string, 0)
for _, singleFilterValue := range v {
filterValues = append(filterValues, *singleFilterValue)
}

convertedCostFilters[k] = strings.Join(filterValues, ",")
}

return convertedCostFilters
}

func convertPlannedBudgetLimitsToSet(plannedBudgetLimits map[string]*budgets.Spend) []interface{} {
if plannedBudgetLimits == nil {
return nil
Expand Down Expand Up @@ -834,11 +807,6 @@ func expandBudgetUnmarshal(d *schema.ResourceData) (*budgets.Budget, error) {
budgetCostFilters[key] = append(budgetCostFilters[key], aws.String(filterValue.(string)))
}
}
} else if costFilters, ok := d.GetOk("cost_filters"); ok {
for k, v := range costFilters.(map[string]interface{}) {
filterValue := v.(string)
budgetCostFilters[k] = append(budgetCostFilters[k], aws.String(filterValue))
}
}

budgetTimePeriodStart, err := timePeriodTimestampFromString(d.Get("time_period_start").(string))
Expand Down
27 changes: 7 additions & 20 deletions internal/service/budgets/budget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestAccBudgetsBudget_basic(t *testing.T) {
CheckDestroy: testAccCheckBudgetDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccBudgetConfig_deprecated(rName),
Config: testAccBudgetConfig_basic(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccBudgetExists(ctx, resourceName, &budget),
acctest.CheckResourceAttrAccountID(resourceName, "account_id"),
Expand All @@ -68,10 +68,8 @@ func TestAccBudgetsBudget_basic(t *testing.T) {
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "cost_filter.*", map[string]string{
"name": "Service",
"values.#": "1",
"values.0": "Amazon Elasticsearch Service",
"values.0": "Amazon Redshift",
}),
resource.TestCheckResourceAttr(resourceName, "cost_filters.%", "1"),
resource.TestCheckResourceAttr(resourceName, "cost_filters.Service", "Amazon Elasticsearch Service"),
resource.TestCheckResourceAttr(resourceName, "limit_amount", "100.0"),
resource.TestCheckResourceAttr(resourceName, "limit_unit", "PERCENTAGE"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
Expand Down Expand Up @@ -113,8 +111,6 @@ func TestAccBudgetsBudget_Name_generated(t *testing.T) {
"values.#": "1",
"values.0": "Amazon Redshift",
}),
resource.TestCheckResourceAttr(resourceName, "cost_filters.%", "1"),
resource.TestCheckResourceAttr(resourceName, "cost_filters.Service", "Amazon Redshift"),
resource.TestCheckResourceAttr(resourceName, "limit_amount", "100.0"),
resource.TestCheckResourceAttr(resourceName, "limit_unit", "PERCENTAGE"),
acctest.CheckResourceAttrNameGenerated(resourceName, "name"),
Expand Down Expand Up @@ -152,7 +148,6 @@ func TestAccBudgetsBudget_namePrefix(t *testing.T) {
testAccBudgetExists(ctx, resourceName, &budget),
resource.TestCheckResourceAttr(resourceName, "budget_type", "SAVINGS_PLANS_UTILIZATION"),
resource.TestCheckResourceAttr(resourceName, "cost_filter.#", "0"),
resource.TestCheckResourceAttr(resourceName, "cost_filters.%", "0"),
resource.TestCheckResourceAttr(resourceName, "limit_amount", "100.0"),
resource.TestCheckResourceAttr(resourceName, "limit_unit", "PERCENTAGE"),
acctest.CheckResourceAttrNameFromPrefix(resourceName, "name", "tf-acc-test-prefix-"),
Expand Down Expand Up @@ -186,7 +181,7 @@ func TestAccBudgetsBudget_disappears(t *testing.T) {
CheckDestroy: testAccCheckBudgetDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccBudgetConfig_deprecated(rName),
Config: testAccBudgetConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccBudgetExists(ctx, resourceName, &budget),
acctest.CheckResourceDisappears(ctx, acctest.Provider, tfbudgets.ResourceBudget(), resourceName),
Expand Down Expand Up @@ -216,7 +211,6 @@ func TestAccBudgetsBudget_autoAdjustDataForecast(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "budget_type", "COST"),
resource.TestCheckResourceAttr(resourceName, "auto_adjust_data.0.auto_adjust_type", "FORECAST"),
resource.TestCheckResourceAttr(resourceName, "cost_filter.#", "0"),
resource.TestCheckResourceAttr(resourceName, "cost_filters.%", "0"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
acctest.CheckResourceAttrGreaterThanValue(resourceName, "limit_amount", "0"),
resource.TestCheckResourceAttr(resourceName, "limit_unit", "USD"),
Expand Down Expand Up @@ -253,7 +247,6 @@ func TestAccBudgetsBudget_autoAdjustDataHistorical(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "auto_adjust_data.0.historical_options.0.lookback_available_periods", "0"),
resource.TestCheckResourceAttrSet(resourceName, "auto_adjust_data.0.last_auto_adjust_time"),
resource.TestCheckResourceAttr(resourceName, "cost_filter.#", "0"),
resource.TestCheckResourceAttr(resourceName, "cost_filters.%", "0"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "time_unit", "MONTHLY"),
acctest.CheckResourceAttrGreaterThanValue(resourceName, "limit_amount", "0"),
Expand All @@ -275,7 +268,6 @@ func TestAccBudgetsBudget_autoAdjustDataHistorical(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "auto_adjust_data.0.historical_options.0.lookback_available_periods", "0"),
resource.TestCheckResourceAttrSet(resourceName, "auto_adjust_data.0.last_auto_adjust_time"),
resource.TestCheckResourceAttr(resourceName, "cost_filter.#", "0"),
resource.TestCheckResourceAttr(resourceName, "cost_filters.%", "0"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "time_unit", "MONTHLY"),
acctest.CheckResourceAttrGreaterThanValue(resourceName, "limit_amount", "0"),
Expand Down Expand Up @@ -320,8 +312,6 @@ func TestAccBudgetsBudget_costTypes(t *testing.T) {
"values.0": acctest.Region(),
"values.1": acctest.AlternateRegion(),
}),
resource.TestCheckResourceAttr(resourceName, "cost_filters.%", "1"),
resource.TestCheckResourceAttr(resourceName, "cost_filters.AZ", strings.Join([]string{acctest.Region(), acctest.AlternateRegion()}, ",")),
resource.TestCheckResourceAttr(resourceName, "cost_types.#", "1"),
resource.TestCheckResourceAttr(resourceName, "cost_types.0.include_credit", "true"),
resource.TestCheckResourceAttr(resourceName, "cost_types.0.include_discount", "false"),
Expand Down Expand Up @@ -361,8 +351,6 @@ func TestAccBudgetsBudget_costTypes(t *testing.T) {
"values.0": acctest.AlternateRegion(),
"values.1": acctest.ThirdRegion(),
}),
resource.TestCheckResourceAttr(resourceName, "cost_filters.%", "1"),
resource.TestCheckResourceAttr(resourceName, "cost_filters.AZ", strings.Join([]string{acctest.AlternateRegion(), acctest.ThirdRegion()}, ",")),
resource.TestCheckResourceAttr(resourceName, "cost_types.#", "1"),
resource.TestCheckResourceAttr(resourceName, "cost_types.0.include_credit", "false"),
resource.TestCheckResourceAttr(resourceName, "cost_types.0.include_discount", "true"),
Expand Down Expand Up @@ -413,7 +401,6 @@ func TestAccBudgetsBudget_notifications(t *testing.T) {
testAccBudgetExists(ctx, resourceName, &budget),
resource.TestCheckResourceAttr(resourceName, "budget_type", "USAGE"),
resource.TestCheckResourceAttr(resourceName, "cost_filter.#", "0"),
resource.TestCheckResourceAttr(resourceName, "cost_filters.%", "0"),
resource.TestCheckResourceAttr(resourceName, "limit_amount", "432.1"),
resource.TestCheckResourceAttr(resourceName, "limit_unit", "GBP"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
Expand Down Expand Up @@ -452,7 +439,6 @@ func TestAccBudgetsBudget_notifications(t *testing.T) {
testAccBudgetExists(ctx, resourceName, &budget),
resource.TestCheckResourceAttr(resourceName, "budget_type", "USAGE"),
resource.TestCheckResourceAttr(resourceName, "cost_filter.#", "0"),
resource.TestCheckResourceAttr(resourceName, "cost_filters.%", "0"),
resource.TestCheckResourceAttr(resourceName, "limit_amount", "432.1"),
resource.TestCheckResourceAttr(resourceName, "limit_unit", "GBP"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
Expand Down Expand Up @@ -587,7 +573,7 @@ func testAccCheckBudgetDestroy(ctx context.Context) resource.TestCheckFunc {
}
}

func testAccBudgetConfig_deprecated(rName string) string {
func testAccBudgetConfig_basic(rName string) string {
return fmt.Sprintf(`
resource "aws_budgets_budget" "test" {
name = %[1]q
Expand All @@ -596,8 +582,9 @@ resource "aws_budgets_budget" "test" {
limit_unit = "PERCENTAGE"
time_unit = "QUARTERLY"
cost_filters = {
Service = "Amazon Elasticsearch Service"
cost_filter {
name = "Service"
values = ["Amazon Redshift"]
}
}
`, rName)
Expand Down
5 changes: 5 additions & 0 deletions website/docs/guides/version-5-upgrade.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Upgrade topics:
- [Resource: aws_acmpca_certificate_authority](#resource-aws_acmpca_certificate_authority)
- [Resource: aws_api_gateway_rest_api](#resource-aws_api_gateway_rest_api)
- [Resource: aws_autoscaling_group](#resource-aws_autoscaling_group)
- [Resource: aws_budgets_budget](#resource-aws_budgets_budget)
- [Resource: aws_ce_anomaly_subscription](#resource-aws_ce_anomaly_subscription)
- [Resource: aws_cloudwatch_event_target](#resource-aws_cloudwatch_event_target)
- [Resource: aws_connect_routing_profile](#resource-aws_connect_queue)
Expand Down Expand Up @@ -113,6 +114,10 @@ The `minimum_compression_size` attribute is now a String type, allowing it to be

The `tags` attribute has been removed. Use the `tag` attribute instead. For use cases requiring dynamic tags, see the [Dynamic Tagging example](../r/autoscaling_group.html.markdown#dynamic-tagging).

## Resource: aws_budgets_budget

The `cost_filters` attribute has been removed.

## Resource: aws_ce_anomaly_subscription

The `threshold` attribute has been removed.
Expand Down
7 changes: 0 additions & 7 deletions website/docs/r/budgets_budget.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ The following arguments are supported:
* `name_prefix` - (Optional) The prefix of the name of a budget. Unique within accounts.
* `budget_type` - (Required) Whether this budget tracks monetary cost or usage.
* `cost_filter` - (Optional) A list of [CostFilter](#cost-filter) name/values pair to apply to budget.
* `cost_filters` - (Optional, **Deprecated**) Map of [CostFilters](#cost-filters) key/value pairs to apply to the budget.
* `cost_types` - (Optional) Object containing [CostTypes](#cost-types) The types of cost included in a budget, such as tax and subscriptions.
* `limit_amount` - (Required) The amount of cost or usage being measured for a budget.
* `limit_unit` - (Required) The unit of measurement used for the budget forecast, actual spend, or budget threshold, such as dollars or GB. See [Spend](http://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/data-type-spend.html) documentation.
Expand Down Expand Up @@ -248,12 +247,6 @@ Based on your choice of budget type, you can choose one or more of the available

Refer to [AWS CostFilter documentation](https://docs.aws.amazon.com/cost-management/latest/userguide/budgets-create-filters.html) for further detail.

### Cost Filters

**Note**: Attribute `cost_filters` is deprecated. Use `cost_filter` instead.

Valid key for `cost_filters` is same as `cost_filter`. Please refer to [Cost Filter](#cost-filter).

### Budget Notification

Valid keys for `notification` parameter.
Expand Down

0 comments on commit 2f44386

Please sign in to comment.