Problem
When you apply a Terraform configuration that uses the azurerm_sql_server resource, you may encounter the following error:
Error: setting database threat detection policy: sql.ServerSecurityAlertPoliciesClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="DataSecurityInvalidUserSuppliedParameter" Message="storageAccountAccessKey parameter can not be null when storageEndpoint parameter is not null\r\nParameter name: storageAccountAccessKey"
Cause
The azurerm_sql_server resource is deprecated. It is based on an older Azure API (2017-03-01-preview) and a "sku" model that Microsoft no longer develops. Microsoft now uses the "vCore" model for SQL servers.
Solutions
To resolve this issue, you must migrate from the deprecated azurerm_sql_server resource to the new azurerm_mssql_server resource. The Azure API does not support both resource types simultaneously, which necessitates two separate resources in the provider. You can find more context in this Azure provider GitHub issue comment.
Solution 1: Rename the Resource in Configuration
You can rename the azurerm_sql_server resource block to azurerm_mssql_server directly in your Terraform configuration. This approach is possible if you are not using any features exclusive to the new API. After a successful apply, you can begin to use the newer features.
For more information on this approach, refer to this comment on a related GitHub issue.
Solution 2: Import the Existing Resource
Alternatively, you can import the existing Azure SQL server into your Terraform state as an azurerm_mssql_server resource.
- Define the
azurerm_mssql_serverresource block in your configuration file with arguments that match your existing infrastructure. - Run the
terraform importcommand to associate the existing Azure resource with your configuration.
Refer to the azurerm_mssql_server import documentation for the specific command. For general guidance on how the import command works, see the Terraform CLI import command documentation.
Additional Information
If you have further questions, you can engage with the larger community on the Terraform Discuss page.