hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.53k stars 4.6k forks source link

Cost management data is not supported for subscription(s), in the provided api-version. Please use api-version │ 2019-10-01 or later. #16334

Open notsopawel opened 2 years ago

notsopawel commented 2 years ago

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

resource "azurerm_consumption_budget_subscription" "budg01" {
  provider        = azurerm.onboarded
  name            = "budg-${var.archtype}-${var.app_id}-${var.env}-${var.sufix}"
  subscription_id = data.azurerm_subscription.onboarded.id
  amount          = var.budget
  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 = [
      ""
    ]
  }

  notification {
    enabled   = true
    threshold = 100.0
    operator  = "EqualTo"
    contact_emails = [
      ""
    ]
  }
}

### Debug Output/Panic Output

```shell
Error: creating Consumption Budget ID: (Consumption Budget Name "xxx" / Scope "/subscriptions/xxx"): consumption.BudgetsClient#CreateOrUpdate: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="404" Message="Cost management data is not supported for subscription(s) xxx in the provided api-version. Please use api-version 2019-10-01 
or later. (Request ID: xxx)"
│
│   with azurerm_consumption_budget_subscription.budg01,
│   on deployment.tf line 41, in resource "azurerm_consumption_budget_subscription" "budg01":
│   41: resource "azurerm_consumption_budget_subscription" "budg01" {
│
│ creating Consumption Budget ID: (Consumption Budget Name "xxx" / Scope "/subscriptions/xxx"): consumption.BudgetsClient#CreateOrUpdate: Failure responding to request: StatusCode=404 --
│ Original Error: autorest/azure: Service returned an error. Status=404 Code="404" Message="Cost management data is not supported for subscription(s) xxx in the provided api-version. Please use api-version
│ 2019-10-01 or later. (Request ID: xxx)"

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

sinbai commented 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",
    ]
  }
}
jakubigla commented 2 years ago

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.

rokeno commented 2 years ago

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.

Netkracker commented 3 months ago

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

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

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"

}

} } image

sinbai commented 2 months ago

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: image

Netkracker commented 2 months ago

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.