Open msl0 opened 1 year ago
Hi @msl0 thanks for opening the issue! Unfortunately, this is by design in Terraform. When the block sql_instance
is not specified, the default value of its nested property is not defined, thus when specifying it during an update will set its value from empty to its default value.
Hi @myc2h6o is there any option to create sql_instance block with default values in state file even if not defined in code?
I found workaround for my problem. I added sql_instance
instead of sql_instance[0]
to ignore_changes
and now it works with existing resources
Hi @msl0 currently due to the design limitation, adding the sql_instance
when it's not there will cause the full resource to be recreated due to some immutable properties nested in this block. To workaround this, unfortunately you may need a direct REST API call like below to set the SqlInstanceSettings.Collation
PUT https://management.azure.com/subscriptions/.../resourceGroups/.../providers/Microsoft.SqlVirtualMachine/SqlVirtualMachines/...?api-version=2023-01-01-preview
{
"properties": {
"virtualMachineResourceId": "/subscriptions/.../resourceGroups/.../providers/Microsoft.Compute/virtualMachines/...",
"provisioningState": "Succeeded",
"sqlImageOffer": "SQL2017-WS2016",
"sqlServerLicenseType": "PAYG",
"sqlManagement": "Full",
"leastPrivilegeMode": "Enabled",
"sqlImageSku": "Developer",
"enableAutomaticUpgrade": true,
"ServerConfigurationsManagementSettings": {
"SqlInstanceSettings": {
"Collation": "SQL_Latin1_General_CP1_CI_AS"
}
}
},
"location": "eastus"
}
GET https://management.azure.com/subscriptions/.../resourceGroups/.../providers/Microsoft.SqlVirtualMachine/SqlVirtualMachines/...?api-version=2023-01-01-preview&$expand=*
will return the full properties
Is there an existing issue for this?
Community Note
Terraform Version
1.3.6
AzureRM Provider Version
3.50.0
Affected Resource(s)/Data Source(s)
azurerm_mssql_virtual_machine
Terraform Configuration Files
Debug Output/Panic Output
Expected Behaviour
Adding
sql_instance
optional block without modifying default values forcollation
,instant_file_initialization_enabled
andlock_pages_in_memory_enabled
shouldn't cause whole resource recreation.Actual Behaviour
Terraform try to recreate
azurerm_mssql_virtual_machine
resource when added sql_instance block to existing resource. Addingsql_instance[0]
toignore_changes
doesn't help.When I commented out
sql_instance
andignore_changes
block it doesn't return recreationThe interesting thing is that this
sql_instance
block is visible in the state file for this resource even though I didn't run theterraform apply
command. Not sure if it is important fact but when I runterraform plan
with debug logging, I see that HTTP response body aboutazurerm_mssql_virtual_machine
showsproperties.serverConfigurationsManagementSettings.sqlInstanceSettings
is empty[DEBUG] provider.terraform-provider-azurerm_v3.50.0_x5: AzureRM Response for https://management.azure.com/subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.SqlVirtualMachine/sqlVirtualMachines/xxx?%24expand=%2A&api-version=2022-02-01
Steps to Reproduce
sql_instance
block -terraform apply
resource "azurerm_mssql_virtual_machine" "example" { virtual_machine_id = data.azurerm_virtual_machine.example.id sql_license_type = "PAYG" r_services_enabled = true sql_connectivity_port = 1433 sql_connectivity_type = "PRIVATE" sql_connectivity_update_password = "test" sql_connectivity_update_username = "test" }
Important Factoids
No response
References
No response