# Error Importing SQL Managed Instance databases

**URL:** <https://discuss.hashicorp.com/t/error-importing-sql-managed-instance-databases/74419>\
**Category:** Terraform\
**Tags:** azure\
**Created:** [April 14, 2025, 7:58pm UTC](https://discuss.hashicorp.com/t/error-importing-sql-managed-instance-databases/74419 "2025-04-14T19:58:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris.fink](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/chris.fink/32/44361_2.png) [@chris.fink](https://discuss.hashicorp.com/u/chris.fink)\
**Post date:** [April 14, 2025, 7:58pm UTC](https://discuss.hashicorp.com/t/error-importing-sql-managed-instance-databases/74419/1 "2025-04-14T19:58:35Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![chris.fink](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/chris.fink/32/44361_2.png) [@chris.fink](https://discuss.hashicorp.com/u/chris.fink)\
**Post date:** [April 18, 2025, 1:00pm UTC](https://discuss.hashicorp.com/t/error-importing-sql-managed-instance-databases/74419/2 "2025-04-18T13:00:12Z")

</div>

I was able to resolve this by deleting the databases, then re-doing how they were defined by using a map(string) to define the databases names.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/hashicorp/original/1X/79bf76adfd92a75631996933098f9ce29d37abf3.svg) [@system](https://discuss.hashicorp.com/u/system)\
**Post date:** [October 15, 2025, 1:01pm UTC](https://discuss.hashicorp.com/t/error-importing-sql-managed-instance-databases/74419/3 "2025-10-15T13:01:09Z")

</div>

Closed on October 15, 2025, 1:01pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
