Skip to content

Instantly share code, notes, and snippets.

@VishDev12
Last active October 12, 2022 07:55
Show Gist options
  • Select an option

  • Save VishDev12/93db08cfa574ed9abeccfde05d60ead4 to your computer and use it in GitHub Desktop.

Select an option

Save VishDev12/93db08cfa574ed9abeccfde05d60ead4 to your computer and use it in GitHub Desktop.
A Packer script to build EKS AMIs with Container Images baked in.
packer {
required_plugins {
amazon = {
version = ">= 0.0.2"
source = "github.com/hashicorp/amazon"
}
}
}
variable "IMAGE" {
type = string
default = "xyz.dkr.ecr.us-east-1.amazonaws.com/app:potato-0.1"
}
variable "SOURCE_AMI" {
type = string
default = "amazon-eks-node-1.23-*"
}
variable "AMI_NAME" {
type = string
}
source "amazon-ebs" "eks-ami" {
ami_name = "${var.AMI_NAME}"
instance_type = "t3.medium"
region = "us-east-1"
iam_instance_profile = "packer-ami-builder"
launch_block_device_mappings {
device_name = "/dev/xvda"
volume_size = 40
volume_type = "gp3"
delete_on_termination = true
}
run_tag {
key = "team"
value = "datascience"
}
run_tag {
key = "app"
value = "potato"
}
run_tag {
key = "env"
value = "prod"
}
source_ami_filter {
filters = {
name = "${var.SOURCE_AMI}"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["602401143452"]
}
ssh_username = "ec2-user"
}
build {
name = "ami-baker"
sources = [
"source.amazon-ebs.eks-ami"
]
provisioner "shell" {
environment_vars = [
"IMAGE=${var.IMAGE}"
]
script = "nerdctl-script.sh"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment