Skip to content

ci: fix and update CI/CD pipelines for packer #4

ci: fix and update CI/CD pipelines for packer

ci: fix and update CI/CD pipelines for packer #4

Workflow file for this run

# This workflow will validate the Packer AMI templates created using the Hashicorp Configuration Language (HCL2)
name: Packer AMI template validation
on:
workflow_dispatch:
pull_request:
branches: [master]
jobs:
validate:
runs-on: ubuntu-latest
environment: ${{ vars.ENVIRONMENT }}
name: Validate packer template for the custom AMI
steps:
- name: Checkout code from branch
uses: actions/checkout@v4
- name: Build artifacts
run: |
zip -r webapp.zip ./
pwd ./webapp
- name: Packer variables
run: |
touch aws/packer/ami.pkrvars.hcl
echo ami_prefix=\"${{ vars.AMI_PREFIX }}\" >> ami.pkrvars.hcl
echo OS=\"${{ vars.OS }}\" >> ami.pkrvars.hcl
echo ubuntu_version=\"${{ vars.VERSION }}\" >> ami.pkrvars.hcl
echo ssh_username=\"${{ vars.SSH_USERNAME }}\" >> ami.pkrvars.hcl
echo subnet_id=\"${{ secrets.SUBNET_ID }}\" >> ami.pkrvars.hcl
echo dev_id=\"${{ secrets.DEV_ID }}\" >> ami.pkrvars.hcl
echo prod_id=\"${{ secrets.PROD_ID }}\" >> ami.pkrvars.hcl
echo source_ami=\"${{ vars.SOURCE_AMI }}\" >> ami.pkrvars.hcl
echo aws_region=\"${{ vars.AWS_REGION }}\" >> ami.pkrvars.hcl
echo instance_type=\"${{ vars.INSTANCE_TYPE}}\" >> ami.pkrvars.hcl
echo volume_type=\"${{ vars.VOLUME_TYPE}}\" >> ami.pkrvars.hcl
echo volume_size=\"${{ vars.VOLUME_SIZE}}\" >> ami.pkrvars.hcl
echo device_name=\"${{ vars.DEVICE_NAME}}\" >> ami.pkrvars.hcl
cp ami.pkrvars.hcl aws/packer
- name: Setup `packer`
uses: hashicorp/setup-packer@main
id: setup
with:
version: "latest"
- name: Packer init, format and validate template with datasources
run: |
cd aws/packer &&
packer fmt .
packer init ami.pkr.hcl
packer validate -syntax-only --var-file=ami.pkrvars.hcl ami.pkr.hcl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}