AWS Budget with filter - Terraform

Hello,

I am trying to write a terraform for AWS and I am stuck in the budget step.
This is my code:

resource “aws_budgets_budget” “project_budget” {
name = “${var.KE}-Budget”
budget_type = “COST”
limit_amount = var.budget
limit_unit = “USD”
time_unit = “MONTHLY”

cost_filter {
  name = "TagKeyValue"
  values = [
    "KE${"$"}${var.KE}"
  ]
}

notification {
  comparison_operator        = "GREATER_THAN"
  notification_type          = "ACTUAL"
  threshold                  = 80
  threshold_type             = "PERCENTAGE"
  subscriber_email_addresses = var.emails
}

notification {
  comparison_operator        = "GREATER_THAN"
  notification_type          = "FORECASTED"
  threshold                  = 100
  threshold_type             = "PERCENTAGE"
  subscriber_email_addresses = var.emails
}

notification {
  comparison_operator        = "GREATER_THAN"
  notification_type          = "ACTUAL"
  threshold                  = 100
  threshold_type             = "PERCENTAGE"
  subscriber_email_addresses = var.emails
}

}

It creates the budget but it is not working as expected, does not show us the current cost and I’ve checked the filter via GUI and I saw this that when you open the ‘value’ field, it doesn’t show anything:

image

But, if I select again the tag KE and then I open the Value field again, I can see everything.
So looks like the tag ‘name’ is failing for some reason.

Has anyone else had this issue?

Best regards,

I updated your configuration a bit for testing purposes and was able to create the budget with a Tag filter. I can see in the AWS Management Console that the the tag KE and the value SomeValue exists, however I also get the spinner when I click on the Values drop-down list:

image

And the Tag drop-down list has nothing because I’ve not enabled any cost allocation tags in my test account. While I can’t validate now because it takes up to 24 hours for the cost allocation tag to activate, I suspect that the KE tag is not activated as a cost allocation tag in your account. If the tag is not available for selection, then the values also don’t show.

The hardcoded values are showing in the budget created by Terraform probably because of differences in validation with the AWS API, i.e. the UI might be doing more validation with the fields.

So if your KE tag is not activated yet, try activating it in CE and see if it works after some time.

Hello!

Thanks for your answer! But I have already enabled the cost allocation tag… Anyway, now you can see it better. If you go to the GUI > edit the budget > edit filter and you click on “Values” you will have this infinite spinner, but if you click on “Tag”, select again the “KE” and then open the “Value” it works fine… so es something from terraform deployment…

Regards,

In that case, I suspect that it’s either an AWS API issue or AWS Management Console issue, in either case opening an AWS support case would be the best course of action.

I yielded the same result when I converted the Terraform configuration to an AWS CLI command that I run in a CloudShell. The budget and the issue in the UI is exactly the same, indicating that it’s an upstream AWS issue.

aws budgets create-budget --account-id <redacted> \
    --budget '{
        "BudgetName": "SomeValue-Budget",
        "BudgetLimit": {
            "Amount": "100",
            "Unit": "USD"
        },
        "CostFilters": {
            "TagKeyValue": [
                "KE$SomeValue"
            ]
        },
        "TimeUnit": "MONTHLY",
        "BudgetType": "COST"
    }' \
    --notifications-with-subscribers '[
        {
            "Notification": {
                "NotificationType": "ACTUAL",
                "ComparisonOperator": "GREATER_THAN",
                "Threshold": 80,
                "ThresholdType": "PERCENTAGE"
            },
            "Subscribers": [
                {
                    "SubscriptionType": "SNS",
                    "Address": "arn:aws:sns:us-east-1:<redacted>:SomeValue-Budget-Topic"
                }
            ]
        },
        {
            "Notification": {
                "NotificationType": "FORECASTED",
                "ComparisonOperator": "GREATER_THAN",
                "Threshold": 100,
                "ThresholdType": "PERCENTAGE"
            },
            "Subscribers": [
                {
                    "SubscriptionType": "SNS",
                    "Address": "arn:aws:sns:us-east-1:<redacted>:SomeValue-Budget-Topic"
                }
            ]
        },
        {
            "Notification": {
                "NotificationType": "ACTUAL",
                "ComparisonOperator": "GREATER_THAN",
                "Threshold": 100,
                "ThresholdType": "PERCENTAGE"
            },
            "Subscribers": [
                {
                    "SubscriptionType": "SNS",
                    "Address": "arn:aws:sns:us-east-1:<redacted>:SomeValue-Budget-Topic"
                }
            ]
        }
    ]'

Hello,

Thank again for the answer.
It’s fine, I am going to ask to AWS support because it is an API issue.

Thank you for your time!