Skip to content

Commit

Permalink
feat(ci/cd): Add terraform infra deploy to stage environment
Browse files Browse the repository at this point in the history
  • Loading branch information
igr-santos committed Nov 7, 2024
1 parent 5c02b06 commit 5d3ca57
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
name: 'Terraform'
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: [ "main", "feature/terraform"]
branches:
- "feature/*"
- "hotfix/*"
paths:
- "instances/**"
- ".github/workflows/terraform-stage.yml"

jobs:
terraform:
name: 'Terraform'
runs-on: ubuntu-latest

steps:
# Checkout the repository to the GitHub Actions runner
# Confira o repositório para o GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3

# Install the latest version of Terraform CLI and configure the Terraform CLI configuration.
# 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
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand All @@ -30,6 +41,10 @@ jobs:
- name: Terraform Validate
run: terraform validate

# Define que iremos trabalhar no ambiente de stage
- name: Terraform Select Workspace
run: terraform workspace select stage

- name: Terraform Plan
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand Down

0 comments on commit 5d3ca57

Please sign in to comment.