Clean up PT Resources #5
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: 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/setup-gcloud@v2.1.0 | |
- 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 init | |
terraform destroy \ | |
--var="kubernetes_config_context=performance-testing" \ | |
--auto-approve | |
- name: Destroy testing resources | |
if: steps.aks.outcome == 'success' || steps.eks.outcome == 'success' || steps.gke.outcome == 'success' | |
run: | | |
cd deployments | |
terraform init | |
terraform destroy \ | |
--var="kubernetes_config_context=performance-testing" \ | |
--var="tyk_version=${{ inputs.tyk_version }}" \ | |
--var="tyk_license=${{ secrets.DASH_LICENSE }}" \ | |
--var="grafana_service_type=LoadBalancer" \ | |
--auto-approve | |
- name: Destroy AKS cluster | |
if: ${{ inputs.cloud == 'Azure' }} | |
run: | | |
cd aks | |
terraform init | |
terraform destroy \ | |
--var="cluster_location=${{ vars.AZURE_CLUSTER_LOCATION }}" \ | |
--var="cluster_machine_type=${{ vars.AZURE_CLUSTER_MACHINE_TYPE }}" \ | |
--auto-approve | |
- name: Destroy EKS cluster | |
if: ${{ inputs.cloud == 'AWS' }} | |
run: | | |
cd eks | |
terraform init | |
terraform destroy \ | |
--var="cluster_location=${{ vars.AWS_CLUSTER_LOCATION }}" \ | |
--var="cluster_machine_type=${{ vars.AWS_CLUSTER_MACHINE_TYPE }}" \ | |
--auto-approve | |
- name: Destroy GKE cluster | |
if: ${{ inputs.cloud == 'GCP' }} | |
run: | | |
cd gke | |
terraform init | |
terraform destroy \ | |
--var="project=${{ secrets.GCP_PROJECT }}" \ | |
--var="cluster_location=${{ vars.GCP_CLUSTER_LOCATION }}" \ | |
--var="cluster_machine_type=${{ vars.GCP_CLUSTER_MACHINE_TYPE }}" \ | |
--auto-approve |