Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
561 views
in Technique[技术] by (71.8m points)

Terraform Import strips quotations from index

I'm trying to import state from Azure via Terraform and save the state to a resource with indexes, such as:

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

I read other threads that say I have to escape the quotation marks, so I did. Even though the quotes are escaped, it seems as though the Terraform compiler is still pulling the quotations out and leaving the characters in place.

Here's the error output that I'm seeing:

Error: Invalid character

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

This character is not used within the language.


Error: Index value required

  on <import-address> line 1:
   1: azurerm_subnet.test_subnets[est-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[est-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

Any thoughts here? Am I doing something wrong or is this a known limitation of the application?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In PowerShell, the import command should be like this:

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

The screenshot here shows the output:

enter image description here

But if you use the cmd in windows, the command you use is also right. See more details about command import.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...