Skip to content

Destroy All Infrastructure #18

Destroy All Infrastructure

Destroy All Infrastructure #18

name: Destroy Infrastructure
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: 'us-east-1'
EKS_CLUSTER_NAME: 'metabaselab'
TF_VAR_db_password: ${{ secrets.RDS_PASSWORD }}
on:
workflow_dispatch:
inputs:
terraform_components:
description: 'Comma-separated list of Terraform components to apply (e.g., vpc,security_group,eks,rds,karpenter)'
required: true
default: 'ingress,vpc,security_group,eks,rds,karpenter'
jobs:
destroy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_DEFAULT_REGION }}
- name: Set up Helm
uses: azure/setup-helm@v1
with:
version: 'v3.13.3'
- name: Set up Terraform
uses: hashicorp/setup-terraform@v1
- name: Terraform Initialize
run: |
cd environments/lab
terraform init
- name: Configure kubectl
if: contains(github.event.inputs.terraform_components, 'ingress') || contains(github.event.inputs.terraform_components, 'karpenter')
run: |
aws eks --region ${{ env.AWS_DEFAULT_REGION }} update-kubeconfig --name ${{ env.EKS_CLUSTER_NAME }}
- name: Delete Istio Ingress Gateway
if: contains(github.event.inputs.terraform_components, 'ingress')
run: |
kubectl delete -f helm/istio/gateway.yaml
# Destroy Karpenter and its dependencies first
- name: Terraform Destroy Karpenter
if: contains(github.event.inputs.terraform_components, 'karpenter')
run: |
cd environments/lab
terraform destroy -target=module.eks_fargate_karpenter.module.karpenter -auto-approve
- name: Terraform Destroy RDS
if: contains(github.event.inputs.terraform_components, 'rds')
run: |
cd environments/lab
terraform destroy -target=module.lab_rds -auto-approve
- name: Terraform Destroy EKS
if: contains(github.event.inputs.terraform_components, 'eks')
run: |
cd environments/lab
terraform destroy -target=module.eks_fargate_karpenter -auto-approve
- name: Terraform Destroy RDS Security Group
if: contains(github.event.inputs.terraform_components, 'rds')
run: |
cd environments/lab
terraform destroy -target=module.security_group -auto-approve
- name: Terraform Destroy VPC
if: contains(github.event.inputs.terraform_components, 'vpc')
run: |
cd environments/lab
terraform destroy -target=module.lab_vpc -auto-approve