-
Notifications
You must be signed in to change notification settings - Fork 1
118 lines (97 loc) · 4.02 KB
/
clean-up.yml
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Clean up PT Resources
on:
workflow_dispatch:
inputs:
cloud:
description: 'Choose Cloud Provider'
required: true
type: choice
default: Azure
options:
- Azure
- AWS
- GCP
env:
provider: ${{ inputs.cloud == 'Azure' && 'aks' || (inputs.cloud == 'AWS' && 'eks' || 'gke') }}
concurrency:
group: ${{ inputs.cloud }}
jobs:
destroy:
name: "Clean up ${{ inputs.cloud }} environment"
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Configure AKS credentials
if: ${{ inputs.cloud == 'Azure' }}
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Configure AWS credentials
if: ${{ inputs.cloud == 'AWS' }}
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.AWS_CLUSTER_LOCATION }}
- name: Authenticate into gcloud
if: ${{ inputs.cloud == 'GCP' }}
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
- name: Install gcloud CLI
if: ${{ inputs.cloud == 'GCP' }}
uses: google-github-actions/[email protected]
- name: Install gcloud k8s auth component
if: ${{ inputs.cloud == 'GCP' }}
run: gcloud components install gke-gcloud-auth-plugin
- name: Install Terraform
uses: hashicorp/setup-terraform@v2
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
terraform_version: "1.8.2"
- name: Create Terraform Cloud descriptors
run: |
cp ${{ env.provider }}/terraform.cloud.tf.example ${{ env.provider }}/terraform.cloud.tf
cp .github/${{ env.provider }}/deployments.tf deployments/terraform.cloud.tf
cp .github/${{ env.provider }}/tests.tf tests/terraform.cloud.tf
- name: Connect to AKS cluster
if: ${{ inputs.cloud == 'Azure' }}
continue-on-error: true
id: aks
run: |
az aks get-credentials \
--resource-group "pt-${{ vars.AZURE_CLUSTER_LOCATION }}" \
--name "pt-${{ vars.AZURE_CLUSTER_LOCATION }}"
kubectl config rename-context $(kubectl config current-context) performance-testing
- name: Connect to EKS cluster
if: ${{ inputs.cloud == 'AWS' }}
id: eks
continue-on-error: true
run: |
aws eks --region "${{ vars.AWS_CLUSTER_LOCATION }}" update-kubeconfig --name "pt-${{ vars.AWS_CLUSTER_LOCATION }}"
kubectl config rename-context $(kubectl config current-context) performance-testing
- name: Connect to GKE cluster
if: ${{ inputs.cloud == 'GCP' }}
id: gke
continue-on-error: true
run: |
gcloud container clusters get-credentials "pt-${{ vars.GCP_CLUSTER_LOCATION }}" \
--zone "${{ vars.GCP_CLUSTER_LOCATION }}" \
--project "${{ secrets.GCP_PROJECT }}"
kubectl config rename-context $(kubectl config current-context) performance-testing
- name: Destroy Tests
if: steps.aks.outcome == 'success' || steps.eks.outcome == 'success' || steps.gke.outcome == 'success'
run: cd tests && terraform destroy --auto-approve
- name: Destroy testing resources
if: steps.aks.outcome == 'success' || steps.eks.outcome == 'success' || steps.gke.outcome == 'success'
run: cd deployments && terraform destroy --auto-approve
- name: Destroy AKS cluster
if: ${{ inputs.cloud == 'Azure' }}
run: cd aks && terraform destroy --auto-approve
- name: Destroy EKS cluster
if: ${{ inputs.cloud == 'AWS' }}
run: cd eks && terraform destroy --auto-approve
- name: Destroy GKE cluster
if: ${{ inputs.cloud == 'GCP' }}
run: cd gke && terraform destroy --auto-approve