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

azurerm_consumption_budget_resource_group start_date is not included in lifecycle ignore_changes #17675

Open dominiquedejaeger-liantis opened 2 years ago

dominiquedejaeger-liantis commented 2 years ago

Is there an existing issue for this?

Community Note

Terraform Version

1.0.0

AzureRM Provider Version

3.0.0

Affected Resource(s)/Data Source(s)

azurerm_consumption_budget_resource_group

Terraform Configuration Files

resource "azurerm_consumption_budget_resource_group" "budget" {
  name              = "${var.budget_name}-${var.env_shortcode}"
  resource_group_id = data.azurerm_resource_group.resource_group.id
  amount            = var.budget_amount
  /*Must be one of Monthly, Quarterly, Annually, BillingMonth, BillingQuarter, or BillingYeary*/
  time_grain        = "Monthly"
  time_period {
    start_date = "2022-07-01T00:00:00.00Z"
  }
  notification  {
    threshold      = 100
    /*Must be one of EqualTo, GreaterThan, or GreaterThanOrEqualTo.*/
    operator       = "GreaterThanOrEqualTo"
    /*The allowed values are Actual and Forecasted*/
    threshold_type = "Actual"
    contact_emails = ["xxx@xxx.com"]
  }

  notification  {
    threshold      = 100
    /*Must be one of EqualTo, GreaterThan, or GreaterThanOrEqualTo.*/
    operator       = "GreaterThanOrEqualTo"
    /*The allowed values are Actual and Forecasted*/
    threshold_type = "Forecasted"
    contact_emails = ["xxx@xxx.com"]
  }
  lifecycle {
    ignore_changes = [time_period]
  }
}

Debug Output/Panic Output

# azurerm_consumption_budget_resource_group.budget must be replaced
-/+ resource "azurerm_consumption_budget_resource_group" "budget" {
name              = "test"
# (3 unchanged attributes hidden)
+notification { # forces replacement
+contact_emails = ["xxx@xxx.com"]
+contact_groups = []
+contact_roles  = []
+enabled        = true
+operator       = "GreaterThanOrEqualTo"
+threshold      = 100
+threshold_type = "Forecasted"
        }
~time_period {
~end_date   = "2032-07-01T00:00:00Z" ->(known after apply)
~start_date = "2022-07-01T00:00:00Z" ->"2022-07-01T00:00:00.00Z"
        }
# (1 unchanged block hidden)
    }
Plan: 1 to add, 0 to change, 1 to destroy.

Expected Behaviour

no recreate but time_period is within ignore_changes

Actual Behaviour

terraform plan does recreate

Steps to Reproduce

No response

Important Factoids

No response

References

No response

averagepyro commented 1 year ago

I was able to work around this by using time_static and time_offset resources for my time_period settings so that I don't have to update the start_date unless I want it to get recreated.

resource "time_static" "budget_start_date" {
  triggers = {
    budget_enabled = var.azure_billing_budget_enabled
    ...
  }
}

resource "time_offset" "budget_end_date" {

  offset_years = 100
  triggers = {
    budget_enabled = var.azure_billing_budget_enabled
    ...
  }
}

resource "azurerm_consumption_budget_subscription" "cb" {
  time_period {
    start_date = formatdate("YYYY-MM-01'T'00:00:00'Z'",time_static.budget_start_date.rfc3339)
    end_date   = formatdate("YYYY-MM-01'T'00:00:00'Z'",time_offset.budget_end_date.rfc3339)
  }
  ...
}