Skip to content

fix(ci/cd): working directory to run command steps #3

fix(ci/cd): working directory to run command steps

fix(ci/cd): working directory to run command steps #3

Workflow file for this run

name: 'Stage deploy using Terraform'
# Garante que esse workflow irá executar apenas quando alterados arquivos
# da pasta instances, que é o local onde está concentrado os arquivos de infraestrura
# declarados com Terraform.
on:
push:
branches:
- "feature/*"
- "hotfix/*"
paths:
- "instances/**"
- ".github/workflows/terraform-stage.yml"
jobs:
terraform:
name: 'Terraform'
runs-on: ubuntu-latest
steps:
# Confira o repositório para o GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
# Instale a versão mais recente do Terraform CLI e defina a configuração do Terraform CLI.
- name: Install Terraform
run: |
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
# Inicia uma serie de comandos para publicar nossa infraestrura.
# Como estamos publicando uma infraestrutura na AWS é necessário garantir
# a configuração dos secrets AWS_ACCESS_KEY_ID e AWS_SECRET_ACCESS_KEY no repositório do Github.
- name: Terraform Initialize
working-directory: ./instances
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: terraform init
- name: Terraform Validate
working-directory: ./instances
run: terraform validate
# Define que iremos trabalhar no ambiente de stage
- name: Terraform Select Workspace
working-directory: ./instances
run: terraform workspace select stage
- name: Terraform Plan
working-directory: ./instances
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: terraform plan
- name: Terraform Apply
working-directory: ./instances
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: terraform apply -auto-approve