provision aws resources #3
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: Infrastructure CI and CD | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- .github/** | |
- infrastructure/** | |
pull_request: | |
paths: | |
- .github/** | |
- infrastructure/** | |
env: | |
TF_VAR_PROJECT_NAME: tarhche | |
TF_VAR_INSTANCE_NAME: backend | |
TF_VAR_SSH_PUBLIC_KEY: $(shell cat ssh-public-key.pub) | |
jobs: | |
ci: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v3 | |
- name: Terraform Format | |
id: fmt | |
run: terraform fmt -check | |
- name: Terraform Init | |
id: init | |
run: terraform init | |
- name: Terraform Validate | |
id: validate | |
run: terraform validate -no-color | |
- name: Terraform Plan | |
run: terraform plan -no-color -input=false | |
continue-on-error: true | |
cd: | |
runs-on: ubuntu-latest | |
# This job will be invoked only on default branch | |
if: ${{ always() && format('refs/heads/{0}', github.event.repository.default_branch) == github.ref }} | |
needs: | |
- ci | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v3 | |
- name: Terraform Apply | |
run: terraform apply -auto-approve -input=false | |
continue-on-error: true |