繁体   English   中英

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

[英]Importing Existing Azure Storage Account Into Terraform Resource

我是 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”,但是我如何导入到该资源的特定模块?

您已声明此资源:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM