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: projeto automatizado completo etapa 3 cicd deploy aplicacao | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Fazer checkout do repositório | |
uses: actions/checkout@v2 | |
- name: Configurar credenciais AWS | |
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: us-east-1 | |
- name: Configurar Terraform | |
uses: hashicorp/setup-terraform@v1 | |
with: | |
terraform_version: 1.0.0 | |
- name: Inicializar Terraform | |
run: terraform init | |
working-directory: Terraform_IaC | |
- name: Aplicar Terraform | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
run: terraform apply -auto-approve -var "aws_access_key=${{ secrets.AWS_ACCESS_KEY_ID }}" -var "aws_secret_key=${{ secrets.AWS_SECRET_ACCESS_KEY }}" | |
working-directory: Terraform_IaC | |
- name: Obter IDs e IPs Públicos das Instâncias | |
id: get_instance_info | |
run: | | |
instance_ids=$(terraform output -json instance_ids | jq -r '.[] | join(",")') | |
instance_public_ips=$(terraform output -json instance_public_ips | jq -r '.[] | join(",")') | |
echo "instance_ids=$instance_ids" >> $GITHUB_ENV | |
echo "instance_public_ips=$instance_public_ips" >> $GITHUB_ENV | |
working-directory: Terraform_IaC | |
- name: Mostrar IDs e IPs Públicos das Instâncias | |
run: | | |
echo "Instance IDs: ${{ env.instance_ids }}" | |
echo "Instance Public IPs: ${{ env.instance_public_ips }}" | |
# - name: Destruir Terraform | |
# env: | |
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
# run: terraform destroy -auto-approve -var "aws_access_key=${{ secrets.AWS_ACCESS_KEY_ID }}" -var "aws_secret_key=${{ secrets.AWS_SECRET_ACCESS_KEY }}" | |
# working-directory: Terraform_IaC |