Ivan jaramillo #32
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: Destroy Terraform resources | |
on: | |
pull_request: | |
branches: [master] | |
types: [closed] | |
jobs: | |
destroy: | |
name: Destroy Terraform resources | |
runs-on: ubuntu-latest | |
env: | |
TF_VAR_my_name: ${{ github.head_ref }} | |
ARM_CLIENT_ID: ${{ vars.ARM_CLIENT_ID }} | |
ARM_SUBSCRIPTION_ID: ${{ vars.ARM_SUBSCRIPTION_ID }} | |
ARM_TENANT_ID: ${{ vars.ARM_TENANT_ID }} | |
ARM_USE_OIDC: 'true' | |
permissions: | |
contents: read | |
id-token: write | |
environment: prod | |
defaults: | |
run: | |
working-directory: 'terraform' | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v3 | |
- name: Init Terraform | |
run: terraform init | |
- name: Destroy resources and delete workspace | |
run: | | |
(terraform workspace select "$TF_VAR_my_name" && \ | |
terraform destroy -auto-approve && \ | |
terraform workspace select default && \ | |
terraform workspace delete "$TF_VAR_my_name") || echo 'No workspace to destroy' |