Last active
January 8, 2021 00:56
-
-
Save deric4/6d8bc4a3b36c65c49570c4156e34509f to your computer and use it in GitHub Desktop.
anthonywritescode #199 json -> hcl example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# variables.pkr.hcl | |
variable ami_name { | |
type = string | |
default = "my-ami" | |
} | |
variable ami_owner { | |
type = list(string) | |
default = [ | |
"099720109477" # canonical | |
] | |
} | |
variable source_ami_name { | |
type = string | |
default = "ubuntu-minimal/images/hvm-ssd/ubuntu-focal-20.04-amd64-*" | |
} | |
variable virt_type { | |
type = string | |
default = "hvm" | |
} | |
variable root_dev_type { | |
type = string | |
default = "ebs" | |
} | |
variable instance_type { | |
type = string | |
default = "t2.micro" | |
} | |
# sources.pkr.hcl | |
source "amazon-ebs" "my-ami" { | |
# don't need to explicity set AWS_CREDS packer will source them for you | |
# https://www.packer.io/docs/builders/amazon#environment-variables | |
# | |
source_ami_filter { | |
owners = var.ami_owner | |
most_recent = true | |
filters = { | |
name = var.source_ami_name | |
virtualization-type = var.virt_type | |
root-device-type = var.root_dev_type | |
} | |
} | |
ami_name = var.ami_name | |
communicator = "ssh" # prefer ssm_session_manager plugin so you can build AMIs in your private subnets | |
ssh_username = "ubuntu" # consider a map of users and lookup() function | |
instance_type = var.instance_type | |
} | |
# build.pkr.hcl | |
build { | |
name = "build_1" | |
source "source.amazon-ebs.my-ami" { | |
name = "my-ami-1" | |
} | |
# depending on the AMI/age of ami, cloud-init can create apt lock files from whatever its doing | |
# that cause later provisioners to fail | |
provisioner "shell" { | |
inline = [ | |
"sudo cloud-init status --wait" | |
] | |
} | |
provisioner "shell" { | |
inline = [ | |
"cd /tmp", | |
"sudo wget https://apt.puppetlabs.com/puppet6-release-focal.deb", | |
"sudo dpkg -i puppet6-release-focal.deb", | |
"sudo DEBIAN_FRONTEND=noninteractive apt-get update -yq", | |
"sudo DEBIAN_FRONTEND=noninteractive apt-get install -yq puppet-agent cowsay" | |
] | |
} | |
post-processor "manifest" { | |
output = "manifest.json" | |
strip_path = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment