Skip to content

refacto: infra: reorganize files (#34) #18

refacto: infra: reorganize files (#34)

refacto: infra: reorganize files (#34) #18

name: Deploying in prod environment via Terraform
on:
push:
branches:
- main
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
S3_REGION: ${{ secrets.S3_REGION }}
S3_BUCKET: ${{ secrets.S3_BUCKET }}
DYNAMODB: ${{ secrets.DYNAMODB }}
TF_VAR_database_username: ${{ secrets.TF_VAR_DATABASE_USERNAME }}
TF_VAR_database_password: ${{ secrets.TF_VAR_DATABASE_PASSWORD }}
jobs:
tf_init:
name: Terraform Init
runs-on: ubuntu-latest
environment: prod
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.3.7
- name: Terraform Init
run: terraform init -backend-config="bucket=$S3_BUCKET" -backend-config="region=$S3_REGION" -backend-config="dynamodb_table=$DYNAMODB"
- name: Terraform Workspace
run: terraform workspace new prod 2> /dev/null || terraform workspace select prod
- name: Terraform Validate
run: terraform validate
tf_plan:
name: Terraform Plan
needs: [tf_init]
runs-on: ubuntu-latest
environment: prod
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.3.7
- name: Terraform Init
run: terraform init -backend-config="bucket=$S3_BUCKET" -backend-config="region=$S3_REGION" -backend-config="dynamodb_table=$DYNAMODB"
- name: Terraform Workspace
run: terraform workspace new prod 2> /dev/null || terraform workspace select prod
- name: Terraform Plan
run: terraform plan -input=false -out=terraform-plan-prod
- name: Upload Terraform Plan
uses: actions/upload-artifact@v2
with:
name: terraform-plan-prod
path: terraform-plan-prod
tf_apply:
name: Terraform Apply
needs: [tf_plan]
runs-on: ubuntu-latest
environment: prod-manual
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.3.7
- name: Terraform Init
run: terraform init -backend-config="bucket=$S3_BUCKET" -backend-config="region=$S3_REGION" -backend-config="dynamodb_table=$DYNAMODB"
- name: Terraform Workspace
run: terraform workspace new prod 2> /dev/null || terraform workspace select prod
- name: Download Terraform Plan
uses: actions/download-artifact@v2
with:
name: terraform-plan-prod
- name: Terraform Apply
run: terraform apply -auto-approve terraform-plan-prod