Skip to content

PRMT-612 | sw612

PRMT-612 | sw612 #48

name: "Deploy - Sandbox"
run-name: "${{ github.event.inputs.git_ref }} | ${{ github.event.inputs.sandbox_name }}"
on:
workflow_dispatch:
inputs:
git_ref:
description: "Branch, tag or SHA to deploy"
required: true
type: "string"
sandbox_name:
description: "Sandbox name [a-z0-9]{1,9}"
required: true
type: "string"
permissions:
pull-requests: write
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
terraform_process:
runs-on: ubuntu-latest
environment: development
steps:
- name: Validate inputs
run: |
if ! [[ "$SANDBOX_NAME" =~ ^[a-z0-9]{1,9}$ ]]; then
echo "Sandbox name must match [a-z0-9]{1,9} (lowercase letters and digits only, 1-9 chars)."
exit 1
fi
env:
SANDBOX_NAME: ${{ github.event.inputs.sandbox_name }}
# Checkout the repository to the GitHub Actions runner
- name: Checkout Base
uses: actions/checkout@v5
with:
ref: main
- 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: View AWS Role
run: aws sts get-caller-identity
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.11.4
terraform_wrapper: false
- name: Terraform Init Base
id: base_init
run: terraform init -backend-config=backend.conf
working-directory: ./infrastructure
shell: bash
- name: Terraform Set Workspace Base
id: base_workspace
run: terraform workspace select -or-create ${{ github.event.inputs.sandbox_name}}
working-directory: ./infrastructure
shell: bash
- name: Terraform Plan Base
id: base_plan
run: |
terraform plan -input=false -no-color -var-file="${{vars.TF_VARS_FILE}}" -out tf-base.plan
working-directory: ./infrastructure
shell: bash
- name: Terraform Apply Base
run: terraform apply -auto-approve -input=false tf-base.plan
working-directory: ./infrastructure
- name: Checkout Branch
uses: actions/checkout@v5
with:
ref: ${{ github.event.inputs.git_ref}}
# Checks that all Terraform configuration files adhere to a canonical format.
- name: Terraform Format
run: terraform fmt -check
working-directory: ./infrastructure
- name: Terraform Init
id: init
run: terraform init -backend-config=backend.conf
working-directory: ./infrastructure
shell: bash
- name: Terraform Set Workspace
id: workspace
run: terraform workspace select ${{ github.event.inputs.sandbox_name}}
working-directory: ./infrastructure
shell: bash
- name: 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: Terraform Apply
run: terraform apply -auto-approve -input=false tf.plan
working-directory: ./infrastructure