Skip to content

Merge branch 'lrnt-020/email-server-setup' into development #307

Merge branch 'lrnt-020/email-server-setup' into development

Merge branch 'lrnt-020/email-server-setup' into development #307

Workflow file for this run

name: Infrastructure Provisioning
on:
push:
branches: [main, staging, development]
pull_request:
branches: [main]
types: [opened, synchronize]
jobs:
workspace:
name: Determining Workspace
runs-on: ubuntu-latest
outputs:
name: ${{ steps.names.outputs.name }}
environment: ${{ steps.names.outputs.environment }}
env:
BRANCH: ${{ github.ref_name }}
steps:
- id: names
name: Name for Terraform Workspace and GitHub Environment
run: |
name=default
environtment=''
if [ "$BRANCH" = "main" ]; then
name=production
environment=${name^}
elif [ "$BRANCH" = "staging" ]; then
name="$BRANCH"
environment=${name^}
else
name=development
if [ "$BRANCH" = "development" ]; then
environment=${name^}
fi
fi
echo name=$name >> "$GITHUB_OUTPUT"
echo environment=$environment >> "$GITHUB_OUTPUT"
provisioning:
name: Terraform Provisioning
runs-on: ubuntu-latest
needs: workspace
environment: ${{ needs.workspace.outputs.environment }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ vars.AWS_REGION }}
TF_VAR_aws_root_id: ${{ secrets.TF_VAR_AWS_ROOT_ID }}
TF_VAR_aws_env_id: ${{ secrets.TF_VAR_AWS_ENV_ID }}
TF_VAR_database_username: ${{ secrets.DATABASE_USERNAME }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: '1.4.6'
- name: Lint check
run: terraform fmt -check
- name: Initialising back-end state
run: terraform init -backend-config back-end/default.tfvars
- name: Validation
run: terraform validate
- name: Planning in default workspace
run: terraform plan
- name: Select ${{ needs.workspace.outputs.name }} workspace
run: terraform workspace select ${{ needs.workspace.outputs.name }}
- name: Planning in ${{ needs.workspace.outputs.name }} workspace
run: terraform plan
- name: Applying on ${{ needs.workspace.outputs.name }} workspace
if: github.event_name == 'push'
run: terraform apply -auto-approve
- name: Applying on default workspace
if: github.event_name == 'push' && github.ref_name == 'main'
run: |
terraform workspace select default
terraform apply -auto-approve