Skip to content

Commit

Permalink
add cost filters to budget resource
Browse files Browse the repository at this point in the history
  • Loading branch information
xchapter7x committed Mar 31, 2018
1 parent 17906ac commit 6f148e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions aws/resource_aws_budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func resourceAwsBudgetSchema() map[string]*schema.Schema {
Type: schema.TypeString,
Required: true,
},
"cost_filters": &schema.Schema{
Type: schema.TypeMap,
Optional: true,
Computed: true,
},
}
}

Expand All @@ -73,6 +78,12 @@ func resourceAwsBudgetCreate(d *schema.ResourceData, meta interface{}) error {
budgetIncludeTax := d.Get("include_tax").(bool)
budgetIncludeSubscriptions := d.Get("include_subscriptions").(bool)
budgetIncludeBlended := d.Get("include_blended").(bool)
budgetCostFilters := make(map[string][]*string)
for k, v := range d.Get("cost_filters").(map[string]interface{}) {
filterValue := v.(string)
budgetCostFilters[k] = append(budgetCostFilters[k], &filterValue)
}

budgetTimePeriodStart, err := time.Parse("2006-01-02_15:04", d.Get("time_period_start").(string))
if err != nil {
return err
Expand Down Expand Up @@ -102,6 +113,7 @@ func resourceAwsBudgetCreate(d *schema.ResourceData, meta interface{}) error {
Start: &budgetTimePeriodStart,
})
budget.SetTimeUnit(budgetTimeUnit)
budget.SetCostFilters(budgetCostFilters)
createBudgetInput := new(budgets.CreateBudgetInput)
createBudgetInput.SetAccountId(accountID)
createBudgetInput.SetBudget(budget)
Expand Down
3 changes: 3 additions & 0 deletions aws/resource_aws_budget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@ resource "aws_budget" "foo" {
time_period_start = "2017-01-01_12:00"
time_period_end = "2018-01-01_12:00"
time_unit = "MONTHLY"
cost_filters {
AZ = "us-east-1"
}
}`, name)
}

0 comments on commit 6f148e8

Please sign in to comment.