Terraform Import strips quotations from index

Viewed 1520

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[\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

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

1 Answers

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.

Related