Terraform Destroy Workflow #11
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 Destroy Workflow | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| terraform-destroy: | |
| name: Terraform Destroy | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v5 | |
| - name: Login to AWS | |
| uses: aws-actions/[email protected] | |
| 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: Setup Terraform | |
| uses: hashicorp/[email protected] | |
| with: | |
| terraform_version: 1.5.7 | |
| - name: Update kubeconfig | |
| run: aws eks update-kubeconfig --name otel-cluster --region us-east-1 | |
| # --------------------------- | |
| # Delete ArgoCD Applications | |
| # --------------------------- | |
| - name: Delete ArgoCD Applications | |
| run: | | |
| kubectl delete application my-app -n argocd --ignore-not-found | |
| kubectl delete application kube-prometheus-stack -n argocd --ignore-not-found | |
| # --------------------------- | |
| # Uninstall Helm Releases | |
| # --------------------------- | |
| - name: Uninstall Helm Releases | |
| run: | | |
| helm uninstall my-app -n my-app-namespace || true | |
| helm uninstall kube-prometheus-stack -n monitoring || true | |
| helm uninstall argocd -n argocd || true | |
| # --------------------------- | |
| # Delete Namespaces | |
| # --------------------------- | |
| - name: Delete Namespaces | |
| run: | | |
| kubectl delete namespace my-app-namespace --ignore-not-found | |
| kubectl delete namespace monitoring --ignore-not-found | |
| kubectl delete namespace argocd --ignore-not-found | |
| # --------------------------- | |
| # Delete CRDs (Prometheus & Grafana) | |
| # --------------------------- | |
| - name: Delete CRDs | |
| run: | | |
| kubectl get crd -o name | grep -E 'prometheus|grafana|alertmanager|servicemonitor|prometheusrule' | xargs -r kubectl delete || true | |
| # --------------------------- | |
| # Cleanup PVCs & PVs | |
| # --------------------------- | |
| - name: Cleanup Persistent Storage | |
| run: | | |
| kubectl delete pvc --all -A || true | |
| kubectl delete pv --all || true | |
| # --------------------------- | |
| # Terraform Destroy | |
| # --------------------------- | |
| - name: Terraform Init | |
| run: terraform init | |
| working-directory: ./Terraform | |
| - name: Terraform Destroy | |
| run: terraform destroy -auto-approve | |
| working-directory: ./Terraform |