I am attempting to create a database using terraform in Azure from a bacpac located in a storage account. According to this documentation it should be doable using the azurerm_mssql_database import block however it throws an error when attempting this.
This is the relevant section of my tf code:
resource "azurerm_mssql_database" "database" {
name = var.database_name
server_id = azurerm_mssql_server.sql_server.id
collation = "SQL_Latin1_General_CP1_CI_AS"
license_type = "LicenseIncluded"
max_size_gb = 4
sku_name = "Basic"
import {
storage_uri = var.bacpac_url
storage_key = var.access_key
storage_key_type = "StorageAccessKey"
administrator_login = var.sql_user
administrator_login_password = var.sql_password
authentication_type = "Sql"
}
However running this returns the following error:
Error: Unsupported block type
on main.tf line 187, in resource "azurerm_mssql_database"
"database":
187: import {
Blocks of type "import" are not expected here.
I think it clearly confusing the import block with an import for bringing existing resources under terraform management. Is there an error in my syntax that is causing this or is there a new approach I should be using? I am using terraform version 1.5.2 and version 3.0.2 of the azurerm provider if that helps.
I have tried using create_mode however that seems to be broken as well
2
Answers
The
import
block was enabled in version 3.27.0 of the AzureRM provider. You would need to update the provider to a minimum of that version, such as with the semantic versioning below:Support for import block for database has been added in azurerm provider version 3.27.0 and above.
https://github.com/hashicorp/terraform-provider-azurerm/pull/18588
https://github.com/hashicorp/terraform-provider-azurerm/releases/tag/v3.27.0
Below works (assuming using latest or version 3.27.0 of azurerm provider).