|
| 1 | +name: Terraform Destroy Template |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + environment: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + default: "dev" |
| 10 | + description: "Specifies the environment of the deployment." |
| 11 | + config: |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + description: "Specifies the configuration folder for the deployment." |
| 15 | + terraform_version: |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + description: "Specifies the terraform version." |
| 19 | + node_version: |
| 20 | + required: true |
| 21 | + type: number |
| 22 | + description: "Specifies the node version." |
| 23 | + working_directory: |
| 24 | + required: true |
| 25 | + type: string |
| 26 | + description: "Specifies the working directory." |
| 27 | + tenant_id: |
| 28 | + required: true |
| 29 | + type: string |
| 30 | + description: "Specifies the tenant id of the deployment." |
| 31 | + subscription_id: |
| 32 | + required: true |
| 33 | + type: string |
| 34 | + description: "Specifies the subscription id of the deployment." |
| 35 | + secrets: |
| 36 | + CLIENT_ID: |
| 37 | + required: true |
| 38 | + description: "Specifies the client id." |
| 39 | + MY_SAMPLE_SECRET: |
| 40 | + required: true |
| 41 | + description: "Specifies a sample secret." |
| 42 | + |
| 43 | +permissions: |
| 44 | + id-token: write |
| 45 | + contents: read |
| 46 | + |
| 47 | +jobs: |
| 48 | + deployment: |
| 49 | + name: Terraform Destroy |
| 50 | + runs-on: [self-hosted] |
| 51 | + continue-on-error: false |
| 52 | + environment: ${{ inputs.environment }} |
| 53 | + if: github.event_name == 'push' || github.event_name == 'release' |
| 54 | + concurrency: |
| 55 | + group: terraform-${{ inputs.config }}-${{ inputs.environment }} |
| 56 | + cancel-in-progress: false |
| 57 | + |
| 58 | + env: |
| 59 | + ARM_TENANT_ID: ${{ inputs.tenant_id }} |
| 60 | + ARM_SUBSCRIPTION_ID: ${{ inputs.subscription_id }} |
| 61 | + ARM_CLIENT_ID: ${{ secrets.CLIENT_ID }} |
| 62 | + ARM_USE_OIDC: true |
| 63 | + |
| 64 | + steps: |
| 65 | + # Setup Node |
| 66 | + - name: Setup Node |
| 67 | + id: node_setup |
| 68 | + uses: actions/setup-node@v4 |
| 69 | + with: |
| 70 | + node-version: ${{ inputs.node_version }} |
| 71 | + |
| 72 | + # Setup Terraform |
| 73 | + - name: Setup Terraform |
| 74 | + id: terraform_setup |
| 75 | + uses: hashicorp/setup-terraform@v3 |
| 76 | + with: |
| 77 | + terraform_version: ${{ inputs.terraform_version }} |
| 78 | + terraform_wrapper: true |
| 79 | + |
| 80 | + # Check Out Repository |
| 81 | + - name: Check Out Repository |
| 82 | + id: checkout_repository |
| 83 | + uses: actions/checkout@v4 |
| 84 | + |
| 85 | + # Terraform Init |
| 86 | + - name: Terraform Init |
| 87 | + working-directory: ${{ inputs.working_directory }} |
| 88 | + run: | |
| 89 | + terraform init -backend-config=../../config/${CONFIG}/azurerm.tfbackend |
| 90 | + env: |
| 91 | + CONFIG: ${{ inputs.config }} |
| 92 | + |
| 93 | + # Terraform Destroy |
| 94 | + - name: Terraform Destroy |
| 95 | + working-directory: ${{ inputs.working_directory }} |
| 96 | + run: | |
| 97 | + terraform apply -var-file="../../config/${CONFIG}/vars.tfvars" -auto-approve -input=false -destroy |
| 98 | + env: |
| 99 | + CONFIG: ${{ inputs.config }} |
| 100 | + TF_VAR_my_secret: ${{ secrets.MY_SAMPLE_SECRET }} |
0 commit comments