Terraform Plan & Apply with Approval #4
This file contains hidden or 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: Terraform Plan & Apply with Approval | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: 'Ambiente de deploy' | |
| required: true | |
| default: 'dev' | |
| type: choice | |
| options: | |
| - dev | |
| - prod | |
| permissions: | |
| id-token: write | |
| contents: read | |
| env: | |
| ARM_USE_OIDC: true | |
| ARM_CLIENT_ID: ${{ vars.ARM_CLIENT_ID }} | |
| ARM_SUBSCRIPTION_ID: ${{ vars.ARM_SUBSCRIPTION_ID }} | |
| ARM_TENANT_ID: ${{ vars.ARM_TENANT_ID }} | |
| jobs: | |
| plan: | |
| name: Terraform Plan | |
| runs-on: ubuntu-latest | |
| env: | |
| ENV_NAME: ${{ github.event.inputs.environment }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: 1.11.2 | |
| - name: Login no Azure | |
| uses: azure/login@v1 | |
| with: | |
| client-id: ${{ env.ARM_CLIENT_ID }} | |
| tenant-id: ${{ env.ARM_TENANT_ID }} | |
| subscription-id: ${{ env.ARM_SUBSCRIPTION_ID }} | |
| - name: Terraform Init | |
| run: terraform init -backend-config="${{ env.ENV_NAME }}.backend.conf" | |
| working-directory: infra | |
| - name: Terraform Validate | |
| run: terraform validate | |
| working-directory: infra | |
| - name: Terraform Plan | |
| run: terraform plan -input=false -out=terraform.plan -var-file="${{ env.ENV_NAME }}.tfvars" | |
| working-directory: infra | |
| - name: Upload Plan | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: terraform-plan | |
| path: infra/terraform.plan | |
| apply: | |
| name: Terraform Apply (Com Aprovação) | |
| runs-on: ubuntu-latest | |
| needs: plan | |
| environment: | |
| name: ${{ github.event.inputs.environment }} | |
| url: https://portal.azure.com | |
| env: | |
| ENV_NAME: ${{ github.event.inputs.environment }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: 1.11.2 | |
| - name: Login no Azure | |
| uses: azure/login@v1 | |
| with: | |
| client-id: ${{ env.ARM_CLIENT_ID }} | |
| tenant-id: ${{ env.ARM_TENANT_ID }} | |
| subscription-id: ${{ env.ARM_SUBSCRIPTION_ID }} | |
| - name: Download Plan | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: terraform-plan | |
| path: ./infra | |
| - name: Terraform Init | |
| run: terraform init -backend-config="${{ env.ENV_NAME }}.backend.conf" | |
| working-directory: infra | |
| - name: Terraform Apply | |
| run: terraform apply -input=false terraform.plan | |
| working-directory: infra |