Packer templates to build MERN stack base images for AWS and Azure from Ubuntu 22.04, provisioned with Ansible.
This repo uses HashiCorp Packer to:
- AWS: Build an EBS-backed AMI (
mern-base-image-{{timestamp}}) inus-east-1from Canonical Ubuntu 22.04. - Azure: Build a Managed Image (
mern-base-image-{{timestamp}}) in resource groupmern-app-rgfrom Canonical Ubuntu 22.04.
Both images are provisioned by the same Ansible playbook (ansible/deploy.yml), so you get consistent base images across clouds.
- Packer (v1.7+)
- Ansible
- AWS: AWS CLI configured (e.g.
aws configure) or env vars; VPC and subnet IDs set inbuild.pkr.hcl - Azure: Azure CLI installed and logged in (
az login)
IaC_Packer/
├── build.pkr.hcl # Packer config: AWS + Azure sources, Ansible provisioner
├── ansible/
│ ├── deploy.yml # Playbook run during image build
│ └── nginx.conf # Nginx config (if used by playbook)
└── README.md
From the repo root:
packer init .packer validate build.pkr.hclpacker build build.pkr.hclTo build only one provider:
# AWS only
packer build -only=amazon-ebs.ubuntu_base build.pkr.hcl
# Azure only
packer build -only=azure-arm.ubuntu_base build.pkr.hcl- AWS (
build.pkr.hcl):vpc_id,subnet_id,region, andami_namecan be adjusted for your account. - Azure:
build_resource_group_name,managed_image_resource_group_name, andmanaged_image_namecan be changed; auth usesaz login(use_azure_cli_auth = true).
- AWS: New AMI ID in
us-east-1with namemern-base-image-<timestamp>. - Azure: New image in
mern-app-rgwith namemern-base-image-<timestamp>.
Use these images when launching EC2 instances or Azure VMs for the MERN/pizza app.