Open notsopawel opened 2 years ago
@notsopawel thank you for opening this issue. In fact, for resource azurerm_consumption_budget_subscription, the api-version used by terraform provider v3.1.0 is 2019-10-01. Also, the following tf configuration works for me. Could you try to repro this issue with the tf configuration below?
provider "azurerm" {
features {}
}
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.1.0"
}
}
}
data "azurerm_subscription" "onboarded" {}
resource "azurerm_consumption_budget_subscription" "budg01" {
name = "budg-sample"
subscription_id = data.azurerm_subscription.onboarded.id
amount = 1000
time_grain = "Monthly"
time_period {
start_date = formatdate("YYYY-MM-01'T'00:00:00Z", timestamp())
#end_date = "2035-06-01T00:00:00Z"
}
notification {
enabled = true
threshold = 90.0
operator = "EqualTo"
contact_emails = [
"foo@example.com",
"bar@example.com",
]
}
notification {
enabled = true
threshold = 100.0
operator = "EqualTo"
contact_emails = [
"foo@example.com",
"bar@example.com",
]
}
}
I am experiencing the same issue and I'm on 3.11.0 azurerm provider version. My TF code is executed by MSI on Azure Container Service by Atlantis.
I am using tf azurerm 3.2.0 and i still experience this issue after a newly created subscription. It hasn't gone away with 3.1.0, i'm afraid.
From what i know you'd have to way 48hrs to be able to create a new budget.
still happens on 3.109.0 so ~100 releases later this issue still persists ;(
locals { budget_limit_start = formatdate("YYYY-MM", timestamp()) budget_amount_default = 100 budget_threshold_low = 85.0 budget_threshold_high = 100.0 budget_threshold_high_forecast = 100.0 budget_contact_default = ["TotalyUnImportantEmail@NoneOfYourBusiness.com"]
so_list = try([var.subscription_context.default_tags.service_owner], local.budget_contact_default)
tc_list = try(split(";", replace(replace(var.subscription_context.default_tags.technical_contact, " ", ""), ",", ";")), local.budget_contact_default) contact_list = distinct(concat(local.so_list, local.tc_list)) }
resource "azurerm_consumption_budget_subscription" "budget_limit" { name = "notification-budget-limit" subscription_id = "/subscriptions/${var.subscription_context.subscription_id}"
amount = try(var.subscription_context.default_tags.budget_alarm_threshold, local.budget_amount_default) time_grain = "Monthly"
time_period { start_date = format("%s-01T00:00:00Z", local.budget_limit_start) }
notification { enabled = true threshold = local.budget_threshold_low operator = "GreaterThan" threshold_type = "Actual" contact_emails = local.contact_list }
notification { enabled = true threshold = local.budget_threshold_high operator = "GreaterThan" threshold_type = "Actual" contact_emails = local.contact_list }
notification { enabled = true threshold = local.budget_threshold_high_forecast operator = "GreaterThan" threshold_type = "Forecasted" contact_emails = local.contact_list }
lifecycle { ignore_changes = [ time_period ] } }
terraform { required_version = "~> 1.3"
required_providers { azurerm = { source = "hashicorp/azurerm" version = "~> 3.62"
}
} }
Hi @Netkracker sorry for you have the same problem and thank you for providing the config. However, after changing some variable values in the provided configuration, everything works fine on my side. Could you reproduce it with the following config? If yes, since I can't reproduce it here, the API version called by Terraform is already 2019-10-01 and the above error is returned by Azure Rest API instead of Terraform , I suggest you contact Microsoft Support for more support. Thanks.
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.109.0"
}
}
}
provider "azurerm" {
features {}
}
locals {
budget_limit_start = formatdate("YYYY-MM", timestamp())
budget_amount_default = 100
budget_threshold_low = 85.0
budget_threshold_high = 100.0
budget_threshold_high_forecast = 100.0
#budget_contact_default = ["TotalyUnImportantEmail@NoneOfYourBusiness.com"]
#service owner or default
#so_list = try([var.subscription_context.default_tags.service_owner], local.budget_contact_default)
#technical contacts or default
#tc_list = try(split(";", replace(replace(var.subscription_context.default_tags.technical_contact, " ", ""), ",", ";")), local.budget_contact_default)
#contact_list = distinct(concat(local.so_list, local.tc_list))
}
data "azurerm_subscription" "onboarded" {}
resource "azurerm_consumption_budget_subscription" "budget_limit" {
name = "notification-budget-limit"
subscription_id = data.azurerm_subscription.onboarded.id #"/subscriptions/${var.subscription_context.subscription_id}"
amount = 100 #try(var.subscription_context.default_tags.budget_alarm_threshold, local.budget_amount_default)
time_grain = "Monthly"
time_period {
start_date = format("%s-01T00:00:00Z", local.budget_limit_start)
}
notification {
enabled = true
threshold = local.budget_threshold_low
operator = "GreaterThan"
threshold_type = "Actual"
contact_emails = [
"foo@example.com",
"bar@example.com",
]
}
notification {
enabled = true
threshold = local.budget_threshold_high
operator = "GreaterThan"
threshold_type = "Actual"
contact_emails = [
"foo@example.com",
"bar@example.com",
]
}
notification {
enabled = true
threshold = local.budget_threshold_high_forecast
operator = "GreaterThan"
threshold_type = "Forecasted"
contact_emails = [
"foo@example.com",
"bar@example.com",
]
}
lifecycle {
ignore_changes = [
time_period
]
}
}
Actual:
Hi @sinbai , sorry for the incomplete config. This seems to be a time-bound issue and only happens when running this config immediately after a subscription has been created. Running it 24 hours later works like a charm, so @rokeno explanations seems very likely.
Is there an existing issue for this?
Community Note
Terraform Version
1.1.4
AzureRM Provider Version
3.1.0
Affected Resource(s)/Data Source(s)
azurerm_consumption_budget_subscription
Terraform Configuration Files
Expected Behaviour
Azure Subscription Consumption Budget should be created
Actual Behaviour
error as above
Steps to Reproduce
No response
Important Factoids
No response
References
No response