-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (65 loc) · 2.26 KB
/
gke-destroy.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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