I’ve deployed a SQL Managed Instance into Azure, with 4 databases, using a for_each statement. The instance and databases were successfully created. However, I need to re-apply the code to make a change to something else and am getting errors that the databases already exist but are not managed via Terraform and that they need to be imported.
When I run the import command, it errors stating that the resource does not exist in the configuration.
I’m using the following command to import:
terraform import “azurerm_mssql_managed_database.sql[1]” “/subscriptions/subscriptionID/Microsoft.Sql/managedIns
tances/sqlinstncename/databases/databasename”
The for_each code:
resource “azurerm_mssql_managed_database” “sql” {
for_each = {
for i in local.databases : i => i
}
name = “${each.value}”
The above is in a Module, not the root main.tf.
Any help would be appreciated.
Thank you!