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

aws_budgets_budget create and update fail with multilpe TagKeyValue cost_filters #13288

Closed
ghost opened this issue May 12, 2020 · 7 comments · Fixed by #9092
Closed

aws_budgets_budget create and update fail with multilpe TagKeyValue cost_filters #13288

ghost opened this issue May 12, 2020 · 7 comments · Fixed by #9092
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/budgets Issues and PRs that pertain to the budgets service.
Milestone

Comments

@ghost
Copy link

ghost commented May 12, 2020

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 Version

Terraform v0.12.24
+ provider.aws v2.41.0

Terraform Configuration Files

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"
  }
}

Expected Behavior

The budget should be created or updated.

Actual Behavior

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" {

Steps to Reproduce

  1. Add aws_budgets_budget resource specified above
  2. terraform apply -> fails with update budget failed error
  3. Comment out the TagKeyValue line
  4. terraform apply -> success
  5. Uncomment the TagKeyValue line
  6. terraform apply -> fails with update budget failed error
  7. Add the specified tags in the AWS Budgets console
  8. terraform apply -> success with no changes
  9. Change some other parameter (not TagKeyValue)
  10. terraform apply -> fails with update budget failed error
  11. Remove one of the tags from TagKeyValue
  12. terraform apply -> success

Additional Context

The 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?

@ghost ghost added the service/budgets Issues and PRs that pertain to the budgets service. label May 12, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label May 12, 2020
@tacoman
Copy link

tacoman commented May 19, 2020

Running into the exact same issue here.

@keien
Copy link

keien commented Jul 23, 2020

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:

https://github.com/terraform-providers/terraform-provider-aws/blob/6d78e329aa9850caa9e5ea48536572001fecfbb6/aws/resource_aws_budgets_budget.go#L129-L133

Additionally, there seems to be some strange things going on to make this mismatched schema fit the API:

https://github.com/terraform-providers/terraform-provider-aws/blob/6d78e329aa9850caa9e5ea48536572001fecfbb6/aws/resource_aws_budgets_budget.go#L560-L564

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.

@atimush
Copy link

atimush commented Sep 6, 2020

Would be super nice to fix it. Experiencing same issue with latest AWS 2.x and 3.x versions

@mcechini
Copy link

Ditto. We have a number of resources in our account that have a tag applied by our infrastructure team, but not consistently... and we aren't adding that tag. So we need our budget to filter out items that:

  • don't have the tag
  • have the tag set to a specific value

I can configure this in the console and CLI... but not terraform.

@foxylion
Copy link

foxylion commented Mar 30, 2021

I'm facing the same issue. Creating a budget via Terraform that is only targeting some PurchaseTypes is not possible.

I've also seen a PR (#9092) that is trying to fix this problem, but it is currently not merged (and has merge conflicts).

@ewbankkit ewbankkit added enhancement Requests to existing resources that expand the functionality or scope. and removed needs-triage Waiting for first response or review from a maintainer. labels Jul 23, 2021
@github-actions github-actions bot added this to the v3.52.0 milestone Jul 27, 2021
@github-actions
Copy link

This functionality has been released in v3.52.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/budgets Issues and PRs that pertain to the budgets service.
Projects
None yet
6 participants