将现有的Azure存储帐户导入Terraform资源

时间:2020-01-14 03:14:13

标签: azure terraform terraform-provider-azure

我是Terraform的新手,我试图将两个不同的现有Azure存储帐户导入到我在Terraform中创建的两个“ azurerm_storage_account”模块中,即“ my_storage_account”和“ my_storage_account_2”。

我遵循了Terraform导入文档并运行:

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

...但是收到以下错误消息:

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)
}

在根模块中,我有:

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

听起来错误消息告诉我写“ storage_account”而不是“ my_storage_account”,但是我如何才能导入该资源的特定模块?

1 个答案:

答案 0 :(得分:1)

您已声明以下资源:

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

terrafrom在内部跟踪ID为azurerm_storage_account.storage_account的资源。

如果您要导入一个存储帐户并告诉terraform您确切是指此资源,则必须在内部使用terraform使用的id。您现在可能会在以下几行中看到差异:

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

如果要由terraform管理多个存储帐户,则每个存储帐户都需要具有自己的唯一资源节。

另请参阅:https://www.terraform.io/docs/import/usage.html

相关问题