Burendo VPN Repo (#114) #104
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Merge to Main" | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- "**/*.tf" | |
- "**/*.j2" | |
- ".github/workflows/**" | |
workflow_dispatch: {} | |
jobs: | |
production: | |
name: "Terraform Apply Production" | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: hashicorp/setup-terraform@v1 | |
with: | |
terraform_version: ${{ secrets.TERRAFORM_VERSION }} | |
- uses: actions/setup-python@v2 | |
with: | |
python-version: "3.x" | |
- name: "Install dependencies" | |
id: deps | |
run: pip install Jinja2 PyYAML boto3 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
role-skip-session-tagging: true | |
aws-access-key-id: ${{ secrets.ACTIONS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.ACTIONS_SECRET_ACCESS_KEY }} | |
role-to-assume: ${{ secrets.AWS_GHA_ROLE }} | |
role-duration-seconds: 900 | |
role-session-name: ${{ github.run_id }}-${{ github.run_number }} | |
aws-region: eu-west-2 | |
- name: "Bootstrap" | |
id: bootstrap | |
run: | | |
python bootstrap.py > ${{ github.workspace }}/${{ github.run_id }}-${{ github.run_number }}.log | |
sed -i "s/Administrator/ci/" variables.tf | |
working-directory: . | |
env: | |
TF_WORKSPACE: default | |
AWS_SECRETS_ROLE: ${{ secrets.AWS_GHA_ROLE }} | |
AWS_DEFAULT_REGION: eu-west-2 | |
- name: "Terraform Init" | |
id: init | |
run: terraform init >> ${{ github.workspace }}/${{ github.run_id }}-${{ github.run_number }}.log | |
env: | |
TF_WORKSPACE: default | |
AWS_DEFAULT_REGION: eu-west-2 | |
- name: "Terraform Apply" | |
id: apply | |
run: | | |
terraform plan -no-color -out terraform.plan >> ${{ github.workspace }}/${{ github.run_id }}-${{ github.run_number }}.log | |
terraform apply -no-color -auto-approve terraform.plan >> ${{ github.workspace }}/${{ github.run_id }}-${{ github.run_number }}.log | |
env: | |
TF_WORKSPACE: default | |
TF_INPUT: false | |
AWS_DEFAULT_REGION: eu-west-2 | |
- name: "Terraform Plan" | |
id: plan | |
if: steps.apply.outcome == 'success' | |
run: terraform plan -no-color -detailed-exitcode >> ${{ github.workspace }}/${{ github.run_id }}-${{ github.run_number }}.log | |
env: | |
TF_WORKSPACE: default | |
TF_INPUT: false | |
AWS_DEFAULT_REGION: eu-west-2 | |
- name: "Terminate Session" | |
if: ${{ always() }} | |
id: terminate-session | |
run: | | |
set -e | |
aws ssm terminate-session --session-id ${{ github.run_id }}-${{ github.run_number }} | |
- name: "Redact Apply Logs PROD" | |
if: ${{ always() }} | |
id: redact-apply-logs-prod | |
run: | | |
sed -i "s/$ACC_PROD/REDACTED/g" ${{ github.workspace }}/${{ github.run_id }}-${{ github.run_number }}.log | |
shell: bash | |
env: | |
ACC_PROD: ${{ secrets.AWS_GHA_ACC_PROD }} | |
- name: "Upload log" | |
uses: actions/upload-artifact@v4 | |
id: upload-log | |
if: ${{ failure() }} | |
with: | |
name: prod-workflow-log | |
path: ${{ github.workspace }}/${{ github.run_id }}-${{ github.run_number }}.log | |
- name: "Report Success" | |
uses: ravsamhq/notify-slack-action@v1 | |
if: ${{ success() }} | |
with: | |
status: success | |
notification_title: ':white_check_mark: *${{ github.workflow }} has succeeded* :white_check_mark:' | |
message_format: '_${{ github.workflow }}_ in *${{ github.repository }}* was triggered by ${{ github.triggering_actor }}' | |
footer: 'Run id is ${{ github.run_id }}' | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_BUILD_NOTIFICATIONS_WEBHOOK }} | |
- name: "Report Failure" | |
uses: ravsamhq/notify-slack-action@v1 | |
if: ${{ failure() }} | |
with: | |
status: failure | |
notification_title: ':alert: *${{ github.workflow }} has failed* :alert:' | |
message_format: '_${{ github.workflow }}_ in *${{ github.repository }}* was triggered by ${{ github.triggering_actor }}' | |
footer: 'Run id is ${{ github.run_id }}' | |
mention_groups: '${{ secrets.SLACK_ENGINEERING_GROUP_ID }}' | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_BUILD_NOTIFICATIONS_WEBHOOK }} |