ci: activate terraform pipeline #1
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: Continuous Integration | |
env: | |
AWS_REGION: ${{ vars.AWS_REGION }} # set this to your preferred AWS region, e.g. us-west-1 | |
ECR_REPOSITORY: ${{ vars.ECR_REPOSITORY }} # set this to your Amazon ECR repository name | |
on: | |
push: | |
branches: ['master'] | |
workflow_dispatch: | |
concurrency: | |
group: ${{ github.head_ref || github.ref_name }} | |
cancel-in-progress: true | |
jobs: | |
terraform-deploy: | |
name: Deploy Terraform | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: terraform | |
env: | |
GITHUB_OWNER: saude-bi | |
permissions: | |
contents: read | |
pull-requests: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }} | |
aws-region: ${{ env.AWS_REGION }} | |
- uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: "1.6.5" | |
- name: Terraform Init | |
id: init | |
run: terraform init | |
continue-on-error: true | |
- name: Terraform Validate | |
id: validate | |
run: terraform validate -no-color | |
continue-on-error: true | |
- name: Terraform Plan | |
id: plan | |
run: terraform plan -no-color -input=false -var ssh_public_key="${{ secrets.SSH_PUBLIC_KEY }}" -var token="${{ secrets.GITHUB_TOKEN }}" | |
continue-on-error: true | |
- name: Terraform Status | |
if: steps.plan.outcome == 'failure' || steps.validate.outcome == 'failure' || steps.init.outcome == 'failure' | |
run: exit 1 | |
- name: Terraform Apply | |
if: github.ref == 'refs/heads/master' && github.event_name == 'push' | |
run: terraform apply -auto-approve -input=false -var ssh_public_key="${{ secrets.SSH_PUBLIC_KEY }}" -var token="${{ secrets.GITHUB_TOKEN }}" |