Skip to content

Deploy/update infrastructure #118

Deploy/update infrastructure

Deploy/update infrastructure #118

Workflow file for this run

name: 'Deploy/update infrastructure '
on:
push:
branches:
- none
workflow_dispatch:
inputs:
environment:
type: environment
description: Select the environment
jobs:
terraform:
name: 'Terraform'
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
defaults:
run:
shell: bash
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v2
# Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
- name: HashiCorp - Setup Terraform
uses: hashicorp/setup-terraform@v1.2.1
- name: Verify Terraform version
run: terraform --version
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
cd terraform && terraform init -migrate-state -input=false
if terraform workspace new ${{ inputs.environment }}
then
echo Workspace created
else
echo workspace already exists
fi
# Generates an execution plan for Terraform
- name: Terraform Init Upgrade
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
cd terraform \
&& terraform workspace select ${{ inputs.environment }} \
&& terraform init -upgrade
- name: Terraform Plan
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
cd terraform \
&& terraform workspace select ${{ inputs.environment }} \
&& terraform plan \
-var-file=${{ inputs.environment }}.tfvars
- name: Terraform Apply
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
cd terraform \
&& terraform workspace select ${{ inputs.environment }} \
&& terraform apply \
-auto-approve \
-var-file=${{ inputs.environment }}.tfvars