Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Terraform not recognizing import block when creating SQL Server database

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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:

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 3.27.0"
    }
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading