We have a module that creates s3 buckets and at the heart of it is the use of publicly available module terraform-aws-modules/s3-bucket/aws/latest. Looking at the source code for that module shows us that the aws_s3_bucket
resource uses a count meta argument
I want to import an existing bucket using the new terraform import block so I’ve defined it like this:
import {
# note the use of [0] to reflect the count meta-arg
to = module.our-bucket-name.this.aws_s3_bucket.this[0]
id = "our-bucket-name"
}
Running terraform plan
then fails with:
│ Error: Invalid expression
│
│ on s3_bucket.tf line 76, in import:
│ 76: to = “module.somebucket.this.aws_s3_bucket.this[0]”
│
│ A single static variable reference is required: only attribute access and
│ indexing with constant keys. No calculations, function calls, template│ expressions, etc are allowed here.
╵
Am I to understand it that resources that use the count meta arg cannot be imported? If so this would be dreadfully disappointing, especially given I’m using a very popular public module here.