Skip to content

Commit

Permalink
feat: adiciona pipeline de destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
nathansouzaa3 committed Oct 8, 2024
1 parent 62b6e30 commit a82d441
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/pipeline_deploy_batch.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: Pipeline de Deploy Batch

on:
push:
branches:
- main
workflow_dispatch:

permissions:
id-token: write
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/pipeline_destroy_lambda.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Pipeline de Destroy Lambda

on:
workflow_dispatch:

permissions:
id-token: write
contents: read

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: "arn:aws:iam::340752815603:role/oidc-github-framework-eml-role"
role-session-name: GitHub_to_AWS_via_FederatedOIDC
aws-region: ${{ env.AWS_REGION }}

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.8.0

- name: Destroy infrastructure
run: |
chmod +x deployment/scripts/destroy_infra_lambda.sh
./deployment/scripts/destroy_infra_lambda.sh ${{ env.AWS_REGION }}
env:
REPO_NAME: "prediction-eml"
AWS_REGION: "us-east-1"
21 changes: 21 additions & 0 deletions deployment/scripts/destroy_infra_lambda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -e

ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
BUCKET_NAME="$ACCOUNT_ID-prediction-eml"
AWS_REGION=$1

# Verifica se o bucket existe
if aws s3api head-bucket --bucket "$BUCKET_NAME" 2>/dev/null; then
echo "O bucket '$BUCKET_NAME' já existe."
else
# Se o bucket não existir, cria o bucket
aws s3api create-bucket --bucket "$BUCKET_NAME" --region us-east-1
echo "Bucket '$BUCKET_NAME' criado com sucesso."
fi

# Inicializa o Terraform
terraform -chdir="deployment/infrastructure/terraform-lambda" init -backend-config="bucket=$BUCKET_NAME" -backend-config="region=$AWS_REGION"

# Comando para destruir a infraestrutura
terraform -chdir="deployment/infrastructure/terraform-lambda" destroy -auto-approve

0 comments on commit a82d441

Please sign in to comment.