Skip to content

main

main #6

name: "Deploy - Pre-prod"
run-name: "${{ github.event.inputs.branch_or_tag }}"
on:
workflow_dispatch:
inputs:
branch_or_tag:
description: "Branch or tag to deploy"
required: true
type: string
default: main
permissions:
pull-requests: write
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
tag_main:
name: Tag main
runs-on: ubuntu-latest
outputs:
version: ${{ steps.versioning.outputs.tag || github.event.inputs.branch_or_tag }}
permissions: write-all
steps:
- name: Checkout main
if: ${{ github.event.inputs.branch_or_tag == 'main' }}
uses: actions/checkout@v5
with:
ref: main
fetch-depth: "0"
- name: Bump version and push tag
if: ${{ github.event.inputs.branch_or_tag == 'main' }}
id: versioning
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: false
DEFAULT_BUMP: patch
- name: View outputs
run: |
echo Tag to deploy: ${{ steps.versioning.outputs.tag || github.event.inputs.branch_or_tag }}
terraform_plan_apply:
name: Terraform Plan/Apply (pre-prod)
runs-on: ubuntu-latest
needs: ["tag_main"]
environment: pre-prod
steps:
- name: Checkout
uses: actions/checkout@v5
with:
ref: ${{ needs.tag_main.outputs.version }}
fetch-depth: "0"
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v5
with:
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }}
role-skip-session-tagging: true
aws-region: ${{ vars.AWS_REGION }}
mask-aws-account-id: true
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.13.3
terraform_wrapper: false
- name: Initialise Terraform
id: init
run: terraform init -backend-config=backend-pre-prod.conf
working-directory: ./infrastructure
shell: bash
- name: Select Terraform Workspace
id: workspace
run: terraform workspace select ${{ secrets.AWS_WORKSPACE }}
working-directory: ./infrastructure
shell: bash
- name: Check Terraform Formatting
run: terraform fmt -check
working-directory: ./infrastructure
- name: Run Terraform Plan
id: plan
run: |
terraform plan -input=false -no-color -var-file="${{vars.TF_VARS_FILE}}" -out tf.plan
working-directory: ./infrastructure
shell: bash
- name: Run Terraform Apply
run: terraform apply -auto-approve -input=false tf.plan
working-directory: ./infrastructure