0
votes

I'm new to Terraform, and I'm trying to import two different existing Azure Storage Accounts into two "azurerm_storage_account" modules I'm creating in Terraform, "my_storage_account" and "my_storage_account_2".

I followed the Terraform import documentation and ran:

terraform import azurerm_storage_account.my_storage_account /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroup/providers/Microsoft.Storage/storageAccounts/myaccount

...but got the following error message:

Error: resource address "azurerm_storage_account.my_storage_account" does not exist in the configuration.

Before importing this resource, please create its configuration in the root module. For example:

resource "azurerm_storage_account" "my_storage_account" {
# (resource arguments)
}

Inside the root module, I have:

resource "azurerm_storage_account" "storage_account" {
# (resource arguments)
}

It sounds like the error message is telling me to write "storage_account" instead of "my_storage_account", but how can I then import to a specific module of that resource?

1

1 Answers

1
votes

You have this resource declared:

resource "azurerm_storage_account" "storage_account" {
# (resource arguments)
}

This resource is tracked internally by terrafrom with the id azurerm_storage_account.storage_account.

If you want to import a storage account and tell terraform that you mean exactly this resource, you have to use the id terraform uses internally. You can probably now see the differences in the following lines:

terraform import azurerm_storage_account.my_storage_account /subcriptions/...
terraform import azurerm_storage_account.storage_account /subcriptions/...

If you want to have multiple storage accounts managed by terraform, each of them will need to have its own unique resource stanza.

See also: https://www.terraform.io/docs/import/usage.html