Introduction
If you are using PowerShell or Unix shells such as bash you see issues with escape rules while you are using either terraform import
or terraform state show
. These will work as expected unless you use for_each
in our resource block. If you use for_each
in the resource block then it is necessary to enclose the whole resource address in single quotes in order to get literal double quotes.
Expected Outcome
In order to refer to resources like aws_instance.web["apache"]
it is necessary to enclose the whole address in single quotes when using terraform import
, terraform state show
, etc.
Prerequisites
- When using PowerShell or Unix bash
Use Case
The resource is using for_each with configuration below
resource "random_uuid" "main" {
for_each = toset(["one", "two"])
}
There are two resources created with for_each
: random_uuid.main["one"]
and random_uuid.main["two"]
Literal double quotes are necessary in the resource address in order for Terraform to be able to locate it in the state and configuration. To obtain literal double quotes in PowerShell or Bash use:
\`"
For example:
terraform import random_uuid.main[\`"one\`"] aabbccdd-eeff-0011-2233-445566778899