Packer builder source_ami_filter for ubuntu 22.04

1.4k views Asked by At

I'm planning to update from ubuntu 20.04 to 22.04, I had changed the config as below

"source_ami_filter": {
          "filters": {
            "virtualization-type": "hvm",
            "name": "*ubuntu/images/hvm-ssd/ubuntu-focal-22.04-amd64-server-*",
            "root-device-type": "ebs"
          }
}

I'm getting error as no matching filters found. So far I had changed the filters to 22.04 but it didn't work

1

There are 1 answers

0
cayleaf On BEST ANSWER

"name": "*ubuntu/images/hvm-ssd/ubuntu-focal-22.04-amd64-server-*",

You name still has focal in it. Change it to jammy

Also the leading * isn't needed (though I suppose it isn't actively hurting anything either).

For ref, this is my working filter:

  source_ami_filter {
    filters = {
      architecture        = "x86_64"
      name                = "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"
      root-device-type    = "ebs"
      virtualization-type = "hvm"
    }
    most_recent = true
    owners      = ["099720109477"]
  }

I get the owner ID by looking up the AMI in my region (https://cloud-images.ubuntu.com/locator/ec2/) & then doing an aws ec2 describe-images.

E.g.

aws ec2 describe-images --filters "Name=image-id,Values=ami-00874d747dde814fa" | grep -e Name -e Architecture -e OwnerId

=>

           "Architecture": "x86_64",
            "OwnerId": "099720109477",
                    "DeviceName": "/dev/sda1",
                    "DeviceName": "/dev/sdb",
                    "VirtualName": "ephemeral0"
                    "DeviceName": "/dev/sdc",
                    "VirtualName": "ephemeral1"
            "Name": "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20230115",
            "RootDeviceName": "/dev/sda1",