Interview Prep/Terraform/Import, Already Exists and State Surgery

`terraform import 'aws_instance.web["api"]' i-0abc` fails in bash with `Error: Index value required` or the address looks mangled.

BeginnerTroubleshootingImport, Already Exists and State Surgery
Answer

Likely causes → Shell quoting. Without single quotes, bash strips the inner double quotes, so Terraform receives aws_instance.web[api].

Diagnose → echo aws_instance.web["api"] prints the mangled address.

Fix →

terraform import 'aws_instance.web["api"]' i-0abc123          # bash/zsh
terraform import 'aws_instance.web[\"api\"]' i-0abc123        # PowerShell

Or avoid quoting entirely with an import block in code.

Prevent → Use import blocks and moved blocks rather than CLI addresses.

All Terraform questions Roadmap: Terraform in production

More on Import, Already Exists and State Surgery