Skip to content

GKE Destroy

GKE Destroy #4

Workflow file for this run

name: "GKE Destroy"
on:
workflow_dispatch:
inputs:
cluster-name:
description: 'Name of GKE cluster to create'
default: "demo-cluster"
gcp-region:
type: choice
description: 'GCP region to create cluster'
default: "us-east5"
options:
- us-east5
- us-central1
- us-east4
gcp-zone:
type: choice
description: 'GCP zone to create cluster'
default: "a"
options:
- a
- b
- c
env:
CLUSTER_NAME: ${{ github.event.inputs.cluster-name || 'demo-cluster' }}
GCP_REGION: ${{ github.event.inputs.gcp-region || 'us-central1' }}
GCP_ZONE: ${{ github.event.inputs.gcp-region || 'us-central1' }}-${{ github.event.inputs.gcp-zone || 'a' }}
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT }}
TF_VAR_project: ${{ secrets.GCP_PROJECT }}
TF_VAR_cluster_name: ${{ github.event.inputs.cluster-name || 'demo-cluster' }}
TF_VAR_region: ${{ github.event.inputs.gcp-region || 'us-central1' }}
TF_VAR_zone: ${{ github.event.inputs.gcp-region || 'us-central1' }}-${{ github.event.inputs.gcp-zone || 'a' }}
jobs:
terraform:
name: "Terraform"
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
defaults:
run:
working-directory: gke_tf
steps:
- name: Checkout
uses: actions/checkout@v3
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: google-github-actions/[email protected]
with:
create_credentials_file: 'true'
workload_identity_provider: ${{ secrets.WIF_POOL }}
service_account: ${{ secrets.SA_EMAIL }}
- id: update-terraform-bucket
name: Create GCP storage bucket
run: sed -i "s/REPLACE_BUCKET/${GCP_PROJECT_ID}-${CLUSTER_NAME}/g" providers.tf
- name: Terraform Init
id: init
run: terraform init
- name: Terraform Apply
run: terraform apply -destroy -auto-approve
- id: delete-bucket
name: Create GCP storage bucket
run: |
gcloud storage rm --recursive gs://${GCP_PROJECT_ID}-${CLUSTER_NAME} --project $GCP_PROJECT_ID --quiet
gcloud storage buckets delete gs://${GCP_PROJECT_ID}-${CLUSTER_NAME} --project $GCP_PROJECT_ID --quiet