Is it possible to add a tag to AWS AMI created with Packer containing name of filtered source_ami?

Viewed 3240

I am building AWS AMI with Packer. The source image is defined by filter source_ami_filter and the source block looks like

source "amazon-ebs" "test-image" {
  ami_name      = "Some AMI Name"
  instance_type = "t2.micro"
  region        = "eu-central-1"
  source_ami_filter {
    filters = {
      name                = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"
      root-device-type    = "ebs"
      virtualization-type = "hvm"
    }
    most_recent = true
    owners      = ["099720109477"]
  }
  tags = {
//    source_ami_name = ...  # how to get it?
  }
  ssh_username = "ubuntu"
}

How to get the name of the used source AMI from canonical?

1 Answers
Related