1

Does someone have experience in building a Packer ec2 with Terraform and can assist me? Basically, I am getting this error for a "null_resource" that represent Packer

   │ Error: Invalid template interpolation value
│
│   on asg.tf line 14, in resource "null_resource" "packer":
│    7:     command = <<EOF
│    8: packer build \
│    9:   -var region=${var.region} \
│   10:   -var vpc_id=${module.vpc.vpc_id} \
│   11:   -var subnet_id="${module.vpc.private_subnets[0]}" \
│   12:   -var instance_type=${var.instance_type} \
│   13:   -var ami_name=${var.ami_name} \
│   14:   -var source_ami=${data.aws_ami.search} \
│   15:   -var image_path=${local.image_complete_path} \
│   16:   template.json
│   17: EOF
│     ├────────────────
│     │ data.aws_ami.search is object with 34 attributes
│
│ Cannot include the given value in a string template: string required.

Would love some help here, thank you all!

1 Answer 1

3

The error message is pretty expressive:

data.aws_ami.search is object with 34 attributes

You need a single value, so you need a way to filter the attributes.

As per Terraform documentation for the aws_ami data source [1], you probably want the name attribute so the value you should look for is:

data.aws_ami.search.name

If you need the AMI ID, then you should use:

data.aws_ami.search.id

This is the same as using data.aws_ami.search.image_id [2].


[1] https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami#name

[2] https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami#image_id

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.