$ packer init .
$ packer fmt .
$ packer validate .
$ packer build aws-ubuntu.pkr.hcl
# Set AWS_ACCESS_KEY_ID & AWS_SECRET_ACCESS_KEY
$ export AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY
$ export AWS_SECRET_ACCESS_KEY=YOUR_SECRET_KEY
Packer AWS – Builders & Provisionars – aws-ubuntu.pkr.hcl
packer { | |
required_plugins { | |
amazon = { | |
version = ">= 0.0.1" | |
source = "github.com/hashicorp/amazon" | |
} | |
} | |
} | |
source "amazon-ebs" "ubuntu" { | |
ami_name = "learn-packer-linux-aws" | |
instance_type = "t2.micro" | |
region = "us-west-2" | |
source_ami_filter { | |
filters = { | |
name = "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*" | |
root-device-type = "ebs" | |
virtualization-type = "hvm" | |
} | |
most_recent = true | |
owners = ["099720109477"] | |
} | |
ssh_username = "ubuntu" | |
} | |
build { | |
sources = [ | |
"source.amazon-ebs.ubuntu" | |
] | |
provisioner "shell" { | |
environment_vars = [ | |
"FOO=hello world", | |
] | |
inline = [ | |
"echo Installing Redis", | |
"sleep 30", | |
"sudo apt-get update", | |
"sudo apt-get install -y redis-server", | |
"echo \"FOO is $FOO\" > example.txt", | |
] | |
} | |
provisioner "shell" { | |
inline = ["echo This provisioner runs last"] | |
} | |
} |
packer { | |
required_plugins { | |
amazon = { | |
version = ">= 0.0.2" | |
source = "github.com/hashicorp/amazon" | |
} | |
} | |
} | |
source "amazon-ebs" "ubuntu" { | |
ami_name = "learn-packer-linux-aws" | |
instance_type = "t2.micro" | |
region = "us-west-2" | |
source_ami_filter { | |
filters = { | |
name = "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*" | |
root-device-type = "ebs" | |
virtualization-type = "hvm" | |
} | |
most_recent = true | |
owners = ["099720109477"] | |
} | |
ssh_username = "ubuntu" | |
} | |
build { | |
sources = [ | |
"source.amazon-ebs.ubuntu" | |
] | |
} |
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND