Dennis Zheleznyak

Dennis Zheleznyak

DevOps Engineer bigpanda

© 2021

Import existing resources the right way

When trying to import resources to a complex setup of Terraform using the following command:

terraform import module.instances.aws_instance.bp_instance["xx-supervisor-xx"] i-12344556

I always got the following error:

Error: Index value required

  on <import-address> line 1:
   1: module.instances.aws_instance.bp_instance[xx-supervisor-xx]

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

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

That’s because escaping for the instance key name is required, like this:

terraform import module.instances.aws_instance.bp_instance[\"xx-supervisor-xx\"] i-12344556