Files
code-dumps/packer/ami_search.pkr.hcl
T

40 lines
741 B
HCL

# Packer file which query for the latest RHEL9 AMI and print it
packer {
required_plugins {
amazon = {
source = "github.com/hashicorp/amazon"
version = "~> 1"
}
}
}
variable "aws_region" {
type = string
default = "${env("AWS_REGION")}"
}
data "amazon-ami" "rhel" {
filters = {
name = "RHEL-9.*HVM_GA*x86_64*GP3"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["amazon"]
region = "${var.aws_region}"
}
source "null" "local" {
communicator = "none"
}
build {
name = "query"
sources = ["null.local"]
provisioner "shell-local" {
inline = ["echo ${data.amazon-ami.rhel.id} ${data.amazon-ami.rhel.name}"]
}
}