Skip to content

Terraform Build and Deploy #51

Terraform Build and Deploy

Terraform Build and Deploy #51

Workflow file for this run

# Use Terraform to init, validate, plan w/ output file and deploy (if changes merged to 'main'). Archive output file used for GHA Artifact for deployment.
name: 'Terraform Build and Deploy'
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
tags:
description: "Google AppScript Trigger for Deployment"
required: false
type: string
permissions:
id-token: write
contents: read
jobs:
automate:
name: 'Terraform Build, Validation and Deployment'
runs-on: ubuntu-latest
env:
TF_VAR_AWS_ROOT_USER: ${{ secrets.AWS_ROOT_USER }}
TF_VAR_AWS_IAM_USER: ${{ secrets.AWS_IAM_USER}}
TF_VAR_AWS_DEPLOYMENT_ROLE: ${{ secrets.AWS_DEPLOYMENT_ROLE}}
defaults:
run:
shell: bash
working-directory: ./deployment/aws/terraform
steps:
- name: Checkout Github repository
uses: actions/checkout@v4
# - name: DEBUG - print default working dir and file contents
# run: pwd && ls
# - name: DEBUG - print workflow dir and file contents
# working-directory: ./.github/workflows/
# run: pwd && ls
# - name: DEBUG - print actions dir and file contents
# working-directory: ./.github/actions/setup-action/
# run: pwd && ls
- name: Initialize runner
uses: ./.github/actions/setup-action
- name: Terraform Init
run: terraform init
- name: Terraform Format
run: terraform fmt -check
- name: Terraform Validate
run: terraform validate
- name: Terraform Plan
run: terraform plan -input=false -out=$GITHUB_SHA
- name: Archive plan file
uses: actions/upload-artifact@v4
with:
name: ${{ github.sha }}
path: ./
# Deployment should only run once changes have been merged into master
- name: Terraform Deploy
if: github.event_name == 'push'
run: terraform apply $GITHUB_SHA