diff --git a/.github/workflows/pipeline_deploy_batch.yml b/.github/workflows/pipeline_deploy_batch.yml index da5b529..c7b37ac 100644 --- a/.github/workflows/pipeline_deploy_batch.yml +++ b/.github/workflows/pipeline_deploy_batch.yml @@ -1,9 +1,7 @@ name: Pipeline de Deploy Batch on: - push: - branches: - - main + workflow_dispatch: permissions: id-token: write diff --git a/.github/workflows/pipeline_destroy_lambda.yml b/.github/workflows/pipeline_destroy_lambda.yml new file mode 100644 index 0000000..db8f246 --- /dev/null +++ b/.github/workflows/pipeline_destroy_lambda.yml @@ -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" diff --git a/deployment/scripts/destroy_infra_lambda.sh b/deployment/scripts/destroy_infra_lambda.sh new file mode 100644 index 0000000..73d2e83 --- /dev/null +++ b/deployment/scripts/destroy_infra_lambda.sh @@ -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