From 065b78d7b0bd0953495dd49a495177a6ba2b8f08 Mon Sep 17 00:00:00 2001 From: kayache Date: Thu, 21 Mar 2019 17:25:41 +0100 Subject: [PATCH] Select the workspace automatically IF we forget to change terraform worksace, terraform will override the .tfstate by wrong enviroment --- cloudwatt/test_snat_lbaas/Makefile | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cloudwatt/test_snat_lbaas/Makefile b/cloudwatt/test_snat_lbaas/Makefile index 7d141c7..0aa4add 100644 --- a/cloudwatt/test_snat_lbaas/Makefile +++ b/cloudwatt/test_snat_lbaas/Makefile @@ -4,18 +4,21 @@ # export INVENTORY=hosts # export COLORTERM=gnome-terminal -init: +switch: + terraform workspace select $$OS_REGION_NAME + +init: switch terraform init -apply: - terraform apply -parallelism=1 -var-file=$$(terraform workspace show).tfvars -auto-approve +apply: switch + terraform apply -parallelism=1 -var-file=$$OS_REGION_NAME.tfvars -auto-approve -inventory: +inventory: switch . ./cloud_stack.rc; \ - terraform-inventory -b $$(cat terraform.tfstate.d/$$(terraform workspace show)/terraform.tfstate | jq -r .modules[0].outputs.bastion_fip.value[0]) -u $$SSH_USER -k $$SSH_KEY -o $$INVENTORY + terraform-inventory -b $$(cat terraform.tfstate.d/$$OS_REGION_NAME/terraform.tfstate | jq -r .modules[0].outputs.bastion_fip.value[0]) -u $$SSH_USER -k $$SSH_KEY -o $$INVENTORY -destroy: - terraform destroy -parallelism=1 -var-file=$$(terraform workspace show).tfvars -force +destroy: switch + terraform destroy -parallelism=1 -var-file=$$OS_REGION_NAME.tfvars -force check: . ./cloud_stack.rc; \