Skip to content

🚚 GitHub Actions for deploying Immutable Infrastructure via HashiCorp

License

Notifications You must be signed in to change notification settings

QubitPi/hashicorp-aws-github-actions

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GitHub Actions for hashicorp-aws

GitHub Actions Marketplace GitHub Workflow Status HashiCorp Packer Badge HashiCorp Terraform Badge Apache License

Immutable Infrastructure as Code via GitHub Action

Application Deployment on AWS through HashiCorp is an opinionated CI/CD GitHub Action that

  1. packages application into and registers AMI image on AWS, then
  2. deploys an EC2 instance of that AMI onto AWS

Error loading hashicorp-aws.png

How to Use HashiCrop AWS GitHub Actions

Step 1 - Setting up HashiCrop Packer & Terraform Template Files

HashiCorp AWS action follows HashiCrop's best practice by expecting a directory called hashicorp located at the root of the repository. An example structure looks like this:

.
└── my-app-repository/
    β”œβ”€β”€ hashicorp/
    β”‚   β”œβ”€β”€ images/
    β”‚   β”‚   └── aws-my-app.pkr.hcl
    β”‚   β”œβ”€β”€ instances/
    β”‚   β”‚   └── aws-my-app.tf
    β”œβ”€β”€ src
    └── ...

Step 2 - Defining Action File

Under regular .github/workflows directory, create a .yml file with a preferred name with the following example contents:

---
name: My App CI/CD

"on":
  pull_request:
  push:
    branches:
      - master

jobs:
  hashicorp:
    name: Publish AMI Image and Deploy it to EC2 through HashiCorp
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      ...

      - name: Publish my-app AMI image and deploy it to EC2 through HashiCorp
        uses: QubitPi/hashicorp-aws-github-actions@master
        with:
          packer-dir: hashicorp/images
          terraform-dir: hashicorp/instances
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ${{ secrets.AWS_REGION }}

Tip

The values of packer-dir and terraform-dir is in accordance with the example directory structure above

Note that the following GitHub Action Secrets needs to be setup

License

The use and distribution terms for hashicorp-aws-github-actions are covered by the Apache License, Version 2.0.