Skip to content

Deploy tagged version to Prod #4

Deploy tagged version to Prod

Deploy tagged version to Prod #4

# .github/workflows/terraform-dev
name: 'Deploy tagged version to Prod'
on:
workflow_dispatch:
inputs:
tagVersion:
description: "What tagged verison do you want to push to prod?"
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: prod
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.tagVersion}}
fetch-depth: '0'
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }}
role-skip-session-tagging: true
aws-region: ${{ vars.AWS_REGION }}
- 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@v2
with:
terraform_version: 1.5.4
terraform_wrapper: false
- name: Terraform Init
id: init
run: terraform init -backend-config=backend-prod.conf
working-directory: ./infrastructure
shell: bash
- name: Terraform Set Workspace
id: workspace
run: terraform workspace select ${{ secrets.AWS_WORKSPACE }}
working-directory: ./infrastructure
shell: bash
# Checks that all Terraform configuration files adhere to a canonical format
- name: Terraform Format
run: terraform fmt -check
working-directory: ./infrastructure
- 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