Destroy All Infrastructure #31
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 All 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: 'lb,vpc,eks,rds,karpenter,stack' | |
jobs: | |
destroy-all: | |
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, 'lb') || contains(github.event.inputs.terraform_components, 'karpenter') || contains(github.event.inputs.terraform_components, 'stack') | |
run: | | |
aws eks --region ${{ env.AWS_DEFAULT_REGION }} update-kubeconfig --name ${{ env.EKS_CLUSTER_NAME }} | |
- name: Trigger Stack Uninstall Workflow | |
if: contains(github.event.inputs.terraform_components, 'stack') | |
run: | | |
curl -XPOST -u "username:${{ secrets.PERSONAL_ACCESS_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
"https://api.github.com/repos/${{ github.repository }}/actions/workflows/uninstall-stack-workflow.yaml/dispatches" \ | |
-d '{"ref":"main"}' | |
- name: Terraform Destroy AWS Load Balancer Controller | |
if: contains(github.event.inputs.terraform_components, 'lb') | |
run: | | |
cd environments/lab | |
terraform destroy -target=helm_release.aws_load_balancer_controller -auto-approve | |
# 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 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 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 VPC | |
if: contains(github.event.inputs.terraform_components, 'vpc') | |
run: | | |
cd environments/lab | |
terraform destroy -target=module.lab_vpc -auto-approve | |
- name: Terraform Destroy Debris | |
if: contains(github.event.inputs.terraform_components, 'vpc') || contains(github.event.inputs.terraform_components, 'eks') | |
run: | | |
cd environments/lab | |
terraform destroy -auto-approve |