_This issue was originally opened by @ndench as hashicorp/terraform#24924. It was migrated here as a result of the provider split. The original body of the issue is below._
When managing an aws_budgets_budget resource, a single cost_filter for TagKeyValue is all that can be specified, if multiple are specified, an error occurs on both create and update.
The create/update must be applied manually in the AWS Budgets Console, and then terraform apply successfully completes as long as there are no required changes to the aws_budgets_budget resource.
Terraform v0.12.24
+ provider.aws v2.41.0
resource "aws_budgets_budget" "test" {
name = "test-budget"
budget_type = "COST"
limit_amount = "1.0"
limit_unit = "USD"
time_period_start = "2020-05-01_00:00"
time_unit = "MONTHLY"
cost_filters = {
TagKeyValue = "user:App$my-app,user:App$my-app-2"
}
}
The budget should be created or updated.
When trying to initially create the resource:
Error: create budget failed: InvalidParameterException: Failed to call CreateBudget for [AccountId: 771882897437] - null
status code: 400, request id: b471c15f-dabb-4656-8267-bc2f4e49fa6e
on main.tf line 525, in resource "aws_budgets_budget" "test":
525: resource "aws_budgets_budget" "test" {
When trying to update a resource:
Error: update budget failed: InvalidParameterException: Failed to call UpdateBudget for [AccountId: 771882897437] - null
status code: 400, request id: 99f2e1b0-0a5f-4ea6-8b23-c5bdacd42f24
on main.tf line 525, in resource "aws_budgets_budget" "test":
525: resource "aws_budgets_budget" "test" {
aws_budgets_budget resource specified aboveterraform apply -> fails with update budget failed errorTagKeyValue lineterraform apply -> successTagKeyValue lineterraform apply -> fails with update budget failed errorterraform apply -> success with no changesterraform apply -> fails with update budget failed errorTagKeyValueterraform apply -> successThe tags specified in TagKeyValue need to be cost allocation tags, I've been using user defined ones which I had to enable in the Billing Console.
It appears that the aws budgets cli takes TagKeyValue as a list, maybe the data type is incorrect?
Running into the exact same issue here.
I've also just run into this issue and was digging around for a workaround, and it does seem that there's some mismatch in data type here
The API doc defines CostFilters as a map of strings to a list of strings. This is not reflected in the schema definition here, which defines it as a map of strings to strings:
Additionally, there seems to be some strange things going on to make this mismatched schema fit the API:
I may be misunderstanding the code, but it looks like this first defines the cost filters correctly as map[string][]*string, but then casts the values from the scheme (which are strings) to an interface{}, and then to a string, and then appends it to the above []*string, which means that any one of these lists for a given key will only ever have one string item. Seems like this whole thing could be avoided if the schema was defined correctly.
I think fixing the schema in the first section and removing the unneeded casting in the second section would resolve this. As it is currently, it makes the budget resources unusable because it can only ever define budgets with single-value cost filters, which is unrealistic as it is common to define budgets that are groups of services and tags.
Would be super nice to fix it. Experiencing same issue with latest AWS 2.x and 3.x versions
Most helpful comment
Running into the exact same issue here.