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.59k stars 4.63k forks source link

Terraform keep updating `time_period` for `azurerm_consumption_budget_management_group` and `azurerm_consumption_budget_subscription` #22922

Open juicybaba opened 1 year ago

juicybaba commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

1.5.4

AzureRM Provider Version

3.69.0

Affected Resource(s)/Data Source(s)

azurerm_consumption_budget_management_group and azurerm_consumption_budget_subscription

Terraform Configuration Files

resource "azurerm_consumption_budget_subscription" "default" {
...
  time_grain      = "Annually"
  time_period {
    start_date = "2023-01-01T00:00:00-05:00"
    end_date   = "2024-12-31T23:59:59-05:00"
  }
...
}

### Debug Output/Panic Output

```shell
see attached screenshot

Expected Behaviour

no change should be detected in next run

Actual Behaviour

It looks like time got configured in a different format than what I provided, or I will say the format that azurerm provider accepts. image

I got the below error when using the format from the above screenshot image

If this is something that needs to be fixed from the provider side, double-check all azurerm_consumption_budget_* resources.

Steps to Reproduce

No response

Important Factoids

No response

References

No response

neil-yechenwei commented 1 year ago

Thanks for raising this issue. Seems service API always returns the format "2023-08-01T00:00:00Z". Hopes below example is helpful.

end_date = format("%s-01-01T23:59:59Z", local.current_year)
juicybaba commented 1 year ago

Thanks for raising this issue. Seems service API always returns the format "2023-08-01T00:00:00Z". Hopes below example is helpful.


end_date = format("%s-01-01T23:59:59Z", local.current_year)

@neil-yechenwei Thanks for the reply. The problem is that in next run(without changing any code) terraform will revert the format back to the format in the code and this will trigger a force replacement of the resource.

Matthew0x commented 11 months ago

I suggest using lifecycle and ignoring the time_perior property (then you wouldn't need to care about any changes. In case of updates you can instead tie the resource lifecycle to the change in the variable I believe, so that the explicit variable change rebuils the whole budget perhaps and not the property change).

In case of dynamically calculated budgets (aka normal IaC code) TF will send a new date on every deployment and the API re-deploys the budget, so you automatically "resolve" 1 more additional issue.

juicybaba commented 9 months ago

I suggest using lifecycle and ignoring the time_perior property (then you wouldn't need to care about any changes. In case of updates you can instead tie the resource lifecycle to the change in the variable I believe, so that the explicit variable change rebuils the whole budget perhaps and not the property change).

In case of dynamically calculated budgets (aka normal IaC code) TF will send a new date on every deployment and the API re-deploys the budget, so you automatically "resolve" 1 more additional issue.

yea, thanks, this is what i am doing