terraform-provider-azurerm: azurerm_mssql_database long_term_retention_policy requires week_of_year and never re-applys clean (reopen #9067)
reopening parts of #9067 the docs say each part is optional, but if i only supply weekly_retention i get an error on apply:
Error: issuing create/update request for Sql Server "usos1sql01-inmp-test" (Database "usos1dbo01-inmp-test") Long Term Retention Policies (Resource Group "usos1rgp01-inmp-test"): sql.BackupLongTermRetentionPoliciesClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: Code="LongTermRetentionMissingWeekOfYear" Message="WeekOfYear is required to be set between 1 and 52 in order to set yearly retention."
again since the docs say optional, i expect not to have to set it, but to work around i put week_of_year = 1 and it applies, but then the very next apply the diff shows:
~ long_term_retention_policy {
~ week_of_year = 0 -> 1
# (3 unchanged attributes hidden)
}
trying to set week_of_year = 0 leads to this error
Error: expected long_term_retention_policy.0.week_of_year to be in the range (1 - 52), got 0
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave “+1” or “me too” comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Terraform (and AzureRM Provider) Version
❯ tf -v Terraform v1.0.4 on windows_amd64
- provider registry.terraform.io/hashicorp/azuread v1.6.0
- provider registry.terraform.io/hashicorp/azurerm v2.72.0
- provider registry.terraform.io/hashicorp/null v3.1.0
- provider registry.terraform.io/microsoft/azuredevops v0.1.6
Affected Resource(s)
azurerm_mssql_database
Terraform Configuration Files
resource "azurerm_mssql_database" "example" {
name = "example"
server_id = azurerm_mssql_server.mgmt.id
elastic_pool_id = azurerm_mssql_elasticpool.mgmt.id
max_size_gb = 100
threat_detection_policy {
state = "Enabled"
email_account_admins = "Enabled"
use_server_default = "Enabled"
storage_endpoint = var.storage_account_blob_endpoint
storage_account_access_key = var.storage_account_access_key
}
short_term_retention_policy {
retention_days = 35
}
long_term_retention_policy {
weekly_retention = "P45D"
# this shouldn't be needed, but get's you past the first error
# week_of_year = 1
}
}
Debug Output
Panic Output
Expected Behaviour
- Can set weekly retention WITHOUT setting week_in_year
- Setting week_in_year to 1 is reflected in state and subsequent runs don’t affect
Actual Behaviour
- week_in_year is required
- rerunning with week_in_year = 1 always shows a difference in plan
Steps to Reproduce
terraform apply
Important Factoids
References
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 53
- Comments: 16 (9 by maintainers)
Commits related to this issue
- azurerm_mssql_database: Accept also 0 for long_term_retention_policy.week_of_year Until there is a proper fix for #13035, allow passing 0, to avoid attempts to modify the resource every time when yea... — committed to orgads/terraform-provider-azurerm by orgads 2 years ago
- azurerm_mssql_database: Accept also 0 for long_term_retention_policy.week_of_year Until there is a proper fix for #13035, allow passing 0, to avoid attempts to modify the resource every time when yea... — committed to orgads/terraform-provider-azurerm by orgads 2 years ago
- sql_retention_policies: Accept also 0 for week_of_year Until there is a proper fix for #13035, allow passing 0, to avoid attempts to modify the resource every time when yearly_retention is 0 or not s... — committed to orgads/terraform-provider-azurerm by orgads 2 years ago
- Default to 1 WoY in long term retention policy (#19665) Fixes https://github.com/hashicorp/terraform-provider-azurerm/issues/13035 — committed to hashicorp/terraform-provider-azurerm by beandrad 2 years ago
- Default to 1 WoY in long term retention policy (#19665) Fixes https://github.com/hashicorp/terraform-provider-azurerm/issues/13035 — committed to favoretti/terraform-provider-azurerm by beandrad 2 years ago
This issue is not fixed with version 3.8.0 or earlier.
week_of_yearis a required parameter, so not setting it or setting it tonullresults in an error during creation.Setting
week_of_yearto any value in the required range (1 - 52) results in proper creation, but it being detected as0during subsequent runs, which then on re-apply leads to the database being updated in place.After a successful creation with
week_of_yearbeing set, one can then adapt the code and set it tonull. That actually results in no change being detected during subsequent runs. But this is an ugly workaround and not a fix.Thank you @beandrad!
With 3.5.0 I can assign
nulltoweek_of_year, and it no longer tries to re-apply every time 👍The issue can be closed.
Any chance of getting this fixed? This is a real pain.
This is not an urgent problem, but it is annoying. To elaborate a bit:
This should be valid:
week_of_yearonly applies to yearly backups. If yearly backups are disabled (set to zero), Azure automatically sets this setting to zero, no matter what the configuration says (config can be 1, the value will be read next time as 0). The azurerm validation for this setting requires 1-52 so the config has to have a nonzero value. Every time Terraform runs it sees a change and an endless cycle of “updates” occurs.Hopefully the fix isn’t any more difficult than changing the validation to allow week_of_year to be 0-52. It would be more accurate to require 1-52 unless yearly_retention is set to “PT0S”, but that relies on Azure not changing their default value, which might not be entirely safe.