Open msl0 opened 1 year ago
I did some additional research on this issue. I noticed that when I'm modifying tags for azurerm_mssql_virtual_machine
then Terraform sends the whole object to API, not only tags (changed part of the object).
PUT /subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.SqlVirtualMachine/sqlVirtualMachines/xxx?api-version=2022-02-01 HTTP/1.1
Host: management.azure.com
User-Agent: Go/go1.19.3 (amd64-windows) go-autorest/v14.2.1 hashicorp/go-azure-sdk/sqlvirtualmachines/2022-02-01 HashiCorp Terraform/1.4.4 (+https://www.terraform.io) Terraform Plugin SDK/2.10.1 terraform-provider-azurerm/dev pid-...
Content-Length: 1146
Content-Type: application/json; charset=utf-8
X-Ms-Correlation-Request-Id: ...
Accept-Encoding: gzip
{"location":"eastus","properties":{"autoBackupSettings":{"enable":false},"serverConfigurationsManagementSettings":{"additionalFeaturesServerConfigurations":{"isRServicesEnabled":false},"sqlConnectivityUpdateSettings":{"connectivityType":"","port":0,"sqlAuthUpdatePassword":"xxx","sqlAuthUpdateUserName":"xxx"},"sqlInstanceSettings":{}},"sqlManagement":"Full","sqlServerLicenseType":"PAYG","storageConfigurationSettings":{"diskConfigurationType":"EXTEND","sqlSystemDbOnDataDisk":false,"sqlTempDbSettings":{"dataFileCount":0,"dataFileSize":0,"dataGrowth":0,"defaultFilePath":"","logFileSize":0,"logGrowth":0,"luns":[]},"storageWorkloadType":""},"virtualMachineResourceId":"/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Compute/virtualMachines/xxx"},"tags":{"tag":"value"}}
So Terraform uses PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SqlVirtualMachine/sqlVirtualMachines/{sqlVirtualMachineName}?api-version=2021-11-01-preview
endpoint
There is also PATCH https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SqlVirtualMachine/sqlVirtualMachines/{sqlVirtualMachineName}?api-version=2021-11-01-preview
endpoint. Maybe this can be used by provider to solve this issue...
Hi @msl0 thanks for opening the issue! The PATCH
of this resource only supports patching tags, thus we may not be able to use this workaround. However, the issue here is indeed a problem, I've done some tests and find out it seems feasible to remove the storageConfiguration
from PUT request when it is an update if the value is not changed (including marked as ignore_changes
), which will not touch the value for storageConfiguration
on service side while updating other properties. I'll take a further look to see if we can make this change and add some test cases to verify it.
@msl0
I've taken a further look, the property storageConfiguration
from the API does not represent the current status. Instead, it stores the last operation detail, which does not make sense. There is an existing issue https://github.com/Azure/azure-sdk-for-go/issues/18434 opened at Azure. As for the issue within the provider, I think we'd better not touch the code until we got some response from API team regarding to how this property will be in the future.
As for the workaround, you can remove the whole storage_configuration
block from the config as well as removing it form the ignore_changes
array, thus it will not show up on the subsequent API requests.
Is there an existing issue for this?
Community Note
Terraform Version
1.4.6
AzureRM Provider Version
3.54.0
Affected Resource(s)/Data Source(s)
azurerm_mssql_virtual_machine
Terraform Configuration Files
Debug Output/Panic Output
Expected Behaviour
Changing the database connection port should not cause a problem with the storage settings when
storage_configuration
is included inignore_changes
list.terraform apply
command should be successfulActual Behaviour
terraform apply
command fails with following error related to mssql storage settings when not modifed and storage settings block has been added toignore_changes
. I noticed similar situation only when resource tags are modified.Steps to Reproduce
sql_connectivity_port
specifiedsql_connectivity_port
using default value (1433) and rerunterraform apply
Important Factoids
No response
References
https://learn.microsoft.com/en-us/rest/api/sqlvm/2021-11-01-preview/sql-virtual-machines/create-or-update?tabs=HTTP https://learn.microsoft.com/en-us/rest/api/sqlvm/2021-11-01-preview/sql-virtual-machines/update?tabs=HTTP