Open dkisby opened 3 years ago
Hi @dkisby,
seems this issue is related to a pre-checking if encryption_enabled
is true and encryption_password
has a empty string. Unfortunately the random_password
resource will provide the result only after apply, while the pre-checking expecting a non-empty string on a earlier stage.
There are few ways to resolve this issue:
encryption_enabled
and only look for encryption_password
. If encryption_password
was set we also enable encryption, if not we disable it. This would also make the pre-checking obsolete.To be honest encryption_enabled
isn't really needed at all, if someone want to encrypt his backup and provided a encryption_password
this should be enough. As a third way Azure could remove this value from API but even this was agreed it won't happen in the near future. I'm tending to the second option, but before raising a PR it would be great to have some feedback if this is a acceptable way.
Hi @wasfree
I had a look at No.1, and this doesn't seem to work. Because although I can omit the auto-backup config from the deployment and rely on the user to configure the auto-backup as per documentation, then if they ever run the deployment again then they are faced with the following issue:
# azurerm_mssql_virtual_machine.db_vm must be replaced
-/+ resource "azurerm_mssql_virtual_machine" "db_vm" {
~ id = "vmId" -> (known after apply)
- r_services_enabled = false -> null
- auto_backup { # forces replacement
- encryption_enabled = true -> null
- retention_period_in_days = 30 -> null
- system_databases_backup_enabled = true -> null
}
+ auto_patching {
+ day_of_week = "Saturday"
+ maintenance_window_duration_in_minutes = 60
+ maintenance_window_starting_hour = 6
}
}
Because this forces replacement, it tries to destroy the azurerm_mssql_virtual_machine and redeploy, but it can't complete this process and reaches timeout during the destroy process. Leaving the SQL VM in a broken state.
No.2 sounds like the answer to me.
Hi @dkisby,
there has to be a misunderstanding in No. 1, the pre-checking has to be disabled in terraform provider code not in terraform configuration. It won't work to configure this outside of terraform because encryption_enabled
has a default value of false which applies if auto_backup block is defined.
Hi @wasfree
Ah, my apologies, I misread No. 1. Either way, I still think No. 2 sounds like the way forward, if pre-checking provides no value then deprecate it.
Atm, we're forced to split out the deployment pipeline jobs to first, generate a secret and then use said secret when deploying backup encryption.
It's not a huge hassle but it's definitely inconvenient.
Hi @wasfree,
I was wondering if the solution you outlined is something that can be implemented? It would make life quite a bit easier / cleaner if it is doable.
Hi @dkisby,
seems this issue is related to a pre-checking if
encryption_enabled
is true andencryption_password
has a empty string. Unfortunately therandom_password
resource will provide the result only after apply, while the pre-checking expecting a non-empty string on a earlier stage.There are few ways to resolve this issue:
- Remove this pre-checking and rely on documentation. So it's up to the user to provider a proper configuration.
- We could deprecate
encryption_enabled
and only look forencryption_password
. Ifencryption_password
was set we also enable encryption, if not we disable it. This would also make the pre-checking obsolete.To be honest
encryption_enabled
isn't really needed at all, if someone want to encrypt his backup and provided aencryption_password
this should be enough. As a third way Azure could remove this value from API but even this was agreed it won't happen in the near future. I'm tending to the second option, but before raising a PR it would be great to have some feedback if this is a acceptable way.
At the moment I can see no solution past this in a CI environment.
We can't run apply with a specific password, then re-edit the stack to add the random password and then re-run an apply.
Surely after two years, there must be a solution/workaround thats usable?
Wasn't sure if I should start a new bug as this is related to the above.
If you add a lifecycle to ignore changes and deploy, then go into the Azure portal and set the auto backup to storage account on with encryption enabled, this pre-check is triggered on the next plan done.
resource "azurerm_mssql_virtual_machine" "sql_vm" {
virtual_machine_id = module.vm_windows.resource_id
sql_license_type = "PAYG"
lifecycle {
ignore_changes = all
}
}
Expected outcome: changes are ignored
Actual outcome: Error on plan
╷
│ Error: auto_backup: `encryption_password` is required when `encryption_enabled` is true
│
│ with azurerm_mssql_virtual_machine.sql_vm,
│ on main.tf line 90, in resource "azurerm_mssql_virtual_machine" "sql_vm":
│ 90: resource "azurerm_mssql_virtual_machine" "sql_vm" {
│
╵
Tested with azurerm 3.116.0 and 4.9.0
@wasfree this issue persists on azurerm 4.9 as well - is it worth updating the v2.x legacy label so it can be noted as an on-going problem. Your option 2 looks reasonable to me.
Terraform (and Provider) Versions
Terraform Version: v1.0.3 azurerm v2.70.0 random v3.1.0
Affected resources
azurerm_mssql_virtual_machine
Terraform configuration files
Expected behaviour
Encryption password is created and used as the encryption_password in auto_backup
Actual behaviour
Steps to Reproduce