packer unable use filter to pick the correct image-id (amzn-Linux2)

1k views Asked by At

I am trying to use packer to create a new AMI. I want to use the base image as "ami-03ededff12e34e59e" ( Amazon Linux 2)

I am using the following filters :

data "amazon-ami"  "amzn2" {
   owners = ["099720109477"]
   most_recent=true
   region = "us-east-1"
   filters = {
     virtualization-type = "hvm"
     architecture = "x86_64"
     root-device-type = "ebs"
     owner-alias = "amazon"
     name = "amzn2-ami-hvm-*"
    }
 }

However, I am getting the following error :

Error: Datasource.Execute failed: No AMI was found matching filters: {

Any thoughts on where I am making a mistake ?

1

There are 1 answers

0
Vasilis Siourdas On

I believe the issue is the owner attribute. For Amazon Linux 2 it should be amazon.

I tend to use the following syntax that grabs the latest AMI:

data "aws_ami" "amazon_linux" {
  most_recent = true
  owners      = ["amazon"]

  filter {
    name   = "name"
    values = ["amzn2-ami-hvm-*-x86_64-gp2"]
  }
}