Github Actions destroy terraform Azure infrastructure is not working

I am able to create AKS cluster using terraform and git workflow. But unable to destroy it from git hub workflow.

I always get message (No changes. No objects need to be destroyed) even the resources are present on portal and workflow completed. I used to delete manually from azure portal.

Can someone please guide me ?
Here is the workflow which I am using

name: abc

on:
workflow_dispatch:
inputs:
environment:
description: “Select the environment. Allowed values are ‘DEV'”
required: true
type: choice
options:
– DEV

  tf-action:
    description: 'Select either to "create" or "destroy" the infrastructure'
    required: true
    type: choice
    options:
      - create
      - destroy

jobs:
AKS-Cluster-Deployment:
runs-on: atc-ubuntu-latest
defaults:
run:
working-directory: terraform
steps:
– name: Checkout
uses: actions/[email protected]

  - name: node
    uses: actions/setup-node@v2
    with:
      node-version: '14'
    
  - name: 'Az CLI login'
    run: |
      echo "Login to Azure"
      az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID  }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
      echo "Select subscription and get AKS credentials"
      az account set -s ${{ secrets.AZURE_SUBSCRIPTION_ID }}

  - name: Setup Terraform
    uses: hashicorp/[email protected]
    with:
      terraform_version: latest

cli_config_credentials_token: ${{ secrets.TFC_TOKEN_ID }}

  - name: Terraform Init
    id: init
    run: terraform init
  
  - name: Terraform Validate
    id: validate
    run: terraform validate

  - name: Terraform Plan
    id: plan
    run: terraform plan
    continue-on-error: true

  - name: Terraform Plan Status
    if: steps.plan.outcome == 'failure'
    run: exit 1

  - name: Terraform Destroy
    run: terraform destroy -auto-approve

  - name: Terraform Output
    run: terraform output 

  • You need to tell us more. When should it be run? (on code deletion?) It would be best if you’d share your github actions code here.

    – 

  • After trigger terraform apply from git action resources has been created, Now I want to delete the resources from git action. Run terraform destroy -auto-approve /home/runner/actions-runner/_work/_temp/5ea6e56c-8668-4081-8f1c-0dede09ee5a2/terraform-bin destroy -auto-approve No changes. No objects need to be destroyed. Either you have not created any objects yet or the existing objects were already deleted outside of Terraform.

    – 




  • Also i am not using specific runner. It picks random runner everytime

    – 

Leave a Comment