I am trying to create a budget alert on GCP that creates a pub/sub message following this documentation. I have tried this both using the cloud console and terraform to no availl
Using cloud console and setting up the pub/sub I get the following error:
The attempted action failed. Please try again.
When trying to do the same thing using terraform with the following:
resource "google_billing_budget" "budget" {
display_name = "test-budget"
billing_account = "xxxx"
budget_filter {
projects = ["projects/xxx"]
credit_types_treatment = "INCLUDE_SPECIFIED_CREDITS"
credit_types = [
"SUSTAINED_USAGE_DISCOUNT",
"DISCOUNT",
"COMMITTED_USAGE_DISCOUNT",
"COMMITTED_USAGE_DISCOUNT_DOLLAR_BASE",
"SUBSCRIPTION_BENEFIT",
]
}
amount {
specified_amount {
currency_code = "EUR"
units = 10
}
}
all_updates_rule {
pubsub_topic = "projects/xxx/topics/budget_alerts"
}
threshold_rules {
threshold_percent = 1.1
spend_basis = "FORECASTED_SPEND"
}
}
I get the following error:
Error 400: Precondition check failed.googleapi: Error 400: Precondition check failed.
The issue in my case was the Domain restricted sharing
on the organisation that was blocking the association of the alert with the pubsub topic. As explained in this documentation you can remove the policy when linking the alert with the topic.