Terraform Import 从索引中删除引号

标签 terraform terraform-provider-azure

我正在尝试通过 Terraform 从 Azure 导入状态并将状态保存到具有索引的资源中,例如:

terraform import azurerm_subnet.test_subnets[\"test-subnet-1\"] /subscriptions/xxxxxx-xxx-xxx-xxxxx/resourceGroups/test-rg/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/test-subnet-1

我读到其他线程说我必须转义引号,所以我做到了。即使引号被转义,Terraform 编译器似乎仍在提取引号并将 \ 字符留在原处。

这是我看到的错误输出:

Error: Invalid character

  on <import-address> line 1:
   1: azurerm_subnet.test_subnets[\test-subnet-1\]

This character is not used within the language.


Error: Index value required

  on <import-address> line 1:
   1: azurerm_subnet.test_subnets[\test-subnet-1\]

Index brackets must contain either a literal number or a literal string.


Error: Invalid character

  on <import-address> line 1:
   1: azurerm_subnet.test_subnets[\test-subnet-1\]

This character is not used within the language.

For information on valid syntax, see:
https://www.terraform.io/docs/internals/resource-addressing.html

这里有什么想法吗?我是在做错什么还是这是应用程序的已知限制?

最佳答案

在 PowerShell 中,导入命令应该是这样的:

terraform import 'azurerm_subnet.test_subnets[\"test-subnet-1\"]' subnet_resource_id

此处的屏幕截图显示了输出:

enter image description here

但是如果你在windows下使用cmd,你用的命令也是对的。查看有关命令的更多详细信息 import .

关于Terraform Import 从索引中删除引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65524231/

相关文章:

environment-variables - 如何在 Terraform 中使用环境变量?

terraform - 是否可以部署具有不同访问级别的 terraform 资源,如果可以,如何?

azure - 使用 for 循环使用 terraform 从 csv 文件中获取值

terraform - 缺少配置版本 Terraform Cloud

azure - 如何使用Terraform for_each资源 block 并对资源 block 进行计数

amazon-web-services - 地形错误 : Extraneous label for module when running terraform init

terraform - 错误: spawn terraform ENOENT during Azure Pipeline Terraform

azure - Azure 上的 Terraform 预留 VM 实例

azure-devops - Terraform - 如何在对象列表中展平列表

azure - 无法使用 terraform 创建 Azure 认知服务