Problem encountered
The issue reported it’s related to importing BACPAC file into a new database using higher version than 1.3.4 of Terraform. Using the version 1.3.4 the import works perfectly fine, but the version 1.3.7 or even 1.4.0(alpha) are facing following issue. I have raised the issue on Terraform GitHub , but I have been redirected here, being told that it is a provider issue. Here is the link.
Terraform Configuration Files
name = "${upper(terraform.workspace)}_MAIN_CONFIG"
server_id = azurerm_mssql_server.sqlsvr.id
max_size_gb = 1
read_scale = false
sku_name = "ElasticPool"
elastic_pool_id = azurerm_mssql_elasticpool.sqlelasticpool.id
zone_redundant = false
collation = "SQL_Latin1_General_CP1_CI_AS"
storage_account_type = "Local"
short_term_retention_policy {
retention_days = 7
}
import {
storage_uri = "https://********.blob.core.windows.net/database/EMPTY_CONFIG.bacpac"
storage_key = data.azurerm_storage_account.storage-account-state.primary_access_key
storage_key_type = "StorageAccessKey"
administrator_login = azurerm_key_vault_secret.kv_secret_db.name
administrator_login_password = azurerm_key_vault_secret.kv_secret_db.value
authentication_type = "Sql"
}
}
resource "azurerm_mssql_database" "db2" {
name = "${upper(terraform.workspace)}_MAIN"
server_id = azurerm_mssql_server.sqlsvr.id
max_size_gb = 5
read_scale = false
sku_name = "ElasticPool"
elastic_pool_id = azurerm_mssql_elasticpool.sqlelasticpool.id
zone_redundant = false
collation = "SQL_Latin1_General_CP1_CI_AS"
storage_account_type = "Local"
short_term_retention_policy {
retention_days = 7
}
import {
storage_uri = "https://**********.blob.core.windows.net/database/EMPTY.bacpac"
storage_key = data.azurerm_storage_account.storage-account-state.primary_access_key
storage_key_type = "StorageAccessKey"
administrator_login = azurerm_key_vault_secret.kv_secret_db.name
administrator_login_password = azurerm_key_vault_secret.kv_secret_db.value
authentication_type = "Sql"
}
}
resource "azurerm_mssql_database" "db3" {
name = "Logistics_${upper(terraform.workspace)}_MAIN"
server_id = azurerm_mssql_server.sqlsvr.id
max_size_gb = 5
read_scale = false
sku_name = "ElasticPool"
elastic_pool_id = azurerm_mssql_elasticpool.sqlelasticpool.id
zone_redundant = false
collation = "SQL_Latin1_General_CP1_CI_AS"
storage_account_type = "Local"
short_term_retention_policy {
retention_days = 7
}
import {
storage_uri = "https://***********.blob.core.windows.net/database/EMPTY_second.bacpac"
storage_key = data.azurerm_storage_account.storage-account-state.primary_access_key
storage_key_type = "StorageAccessKey"
administrator_login = azurerm_key_vault_secret.kv_secret_db.name
administrator_login_password = azurerm_key_vault_secret.kv_secret_db.value
authentication_type = "Sql"
}
}
Expected Behavior
It should have successfully deployed all 3 database with no errors, instead it just deploys one if them.
Actual Behavior
In the past terraform version (1.3.4) would have deployed the bacpac in the new databases successfully, but using the newer version (1.3.7) it fails from the first run and will work only on the second run after deleting the databases manually.
│ Error: while import bacpac into the new database PROD_MAIN (Resource Group rg): Code=“ImportExportJobError” Message=“The ImportExport operation with Request Id ‘3775c190-8b1a-4b46-b9a7-5dd54de98884’ failed due to 'Could not import package.\nWarning SQL0: A project which specifies SQL Server 2017 as the target platform may experience compatibility issues with Microsoft Azure SQL Database v12.\nWarning SQL72012: The object [data_0] exists in the target, but it will not be dropped even though you selected the ‘Generate drop statements for objects that are in the target database but that are not in the source’ check box.\nWarning SQL72012: The object [log] exists in the target, but it will not be dropped even though you '.”
│
│ with azurerm_mssql_database.db2,
│ on sql-db.tf line 100, in resource “azurerm_mssql_database” “db2”:
│ 100: resource “azurerm_mssql_database” “db2” {
Provider version
- azurerm v3.41.0
Steps to Reproduce
- terraform init
- terraform apply
- deployment fails with error mentioned before
- delete manually the databases
- terraform apply