Deploy or Destroy #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: Deploy or Destroy | |
on: | |
workflow_dispatch: | |
inputs: | |
destroy_flag: | |
description: 'Flag to trigger destroy' | |
required: true | |
default: "false" | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
# Passo 1: Checkout do código | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
# Passo 2: Configurar as credenciais da AWS | |
- name: Configure 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 }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
# Passo 3: Instalar o Terraform | |
- name: Set up Terraform | |
uses: hashicorp/setup-terraform@v1 | |
# Passo 4: Inicializar o Terraform com o backend remoto | |
- name: Initialize Terraform | |
run: terraform init | |
# Passo 5: Aplicar ou Destruir a Infraestrutura | |
- name: Apply or Destroy Terraform | |
run: | | |
if [ "${{ github.event.inputs.destroy_flag }}" == "true" ]; then | |
terraform destroy -auto-approve | |
else | |
terraform apply -auto-approve | |
fi |