From 9ccd1dcd4435ee467408e157f1d5a8952c263b89 Mon Sep 17 00:00:00 2001 From: Florian Reinhold Date: Tue, 12 Apr 2022 23:41:42 +0200 Subject: [PATCH] fix(ops.management-cluster): destroy and delete workspace --- ...ent-cluster-terraform-apply-on-hcloud.yaml | 2 +- ...-cluster-terraform-destroy-on-hcloud.yaml} | 30 ++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) rename .github/workflows/{management-cluster-terraform-destroy-and-delete-workspace.yaml => management-cluster-terraform-destroy-on-hcloud.yaml} (60%) diff --git a/.github/workflows/management-cluster-terraform-apply-on-hcloud.yaml b/.github/workflows/management-cluster-terraform-apply-on-hcloud.yaml index 0dd06f5..fe668cb 100644 --- a/.github/workflows/management-cluster-terraform-apply-on-hcloud.yaml +++ b/.github/workflows/management-cluster-terraform-apply-on-hcloud.yaml @@ -1,4 +1,4 @@ -name: "terraform apply on hcloud" +name: "management cluster terraform apply on hcloud" on: workflow_call: diff --git a/.github/workflows/management-cluster-terraform-destroy-and-delete-workspace.yaml b/.github/workflows/management-cluster-terraform-destroy-on-hcloud.yaml similarity index 60% rename from .github/workflows/management-cluster-terraform-destroy-and-delete-workspace.yaml rename to .github/workflows/management-cluster-terraform-destroy-on-hcloud.yaml index bfab2d5..72f588a 100644 --- a/.github/workflows/management-cluster-terraform-destroy-and-delete-workspace.yaml +++ b/.github/workflows/management-cluster-terraform-destroy-on-hcloud.yaml @@ -15,6 +15,12 @@ on: secrets: tf_api_token: required: true + hcloud_secret: + required: true + hcloud_ssh_key_private: + required: true + hcloud_ssh_key_public: + required: true jobs: terraform: @@ -39,17 +45,27 @@ jobs: with: cli_config_credentials_token: ${{ secrets.tf_api_token }} - # Selecting correct workspace - - name: Terraform Workspace Select - run: terraform workspace select ${{ inputs.workspace }} - # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. - name: Terraform Init - run: terraform init + run: TF_WORKSPACE=fallback terraform init -input=false - # Destroy + # Selecting correct workspace (and create if not exist) + - name: Terraform Workspace Select + run: terraform workspace select ${{ inputs.workspace }} || terraform workspace new ${{ inputs.workspace }} + + # Destroy ressources - name: Terraform Destroy - run: terraform destroy -auto-approve + run: | + terraform destroy -auto-approve -var-file=${{ inputs.var_file }} \ + -var prefix="${{ inputs.prefix }}" \ + -var hcloud_secret="${{ secrets.hcloud_secret }}" \ + -var hcloud_ssh_key_private="${{ secrets.hcloud_ssh_key_private }}" \ + -var hcloud_ssh_key_public="${{ secrets.hcloud_ssh_key_public }}" + + # Selecting fallback workspace + - name: Terraform Workspace Select + run: terraform workspace select fallback + # Delete workspace - name: Terraform Workspace delete run: terraform workspace delete -force ${{ inputs.workspace }}