Skip to content

Commit fd3a7d2

Browse files
authored
Avoid accidental total destruction (#308)
This adds accidental destroy protection with a flag to override interaction for automated purposes. ```bash boeboe@Boeboe-NUC-WORK:~/Git/tetrate/tetrate-service-bridge-sandbox (delete-confirm) $ make destroy Do you really want to destroy (y/n)? Destroy canceled. boeboe@Boeboe-NUC-WORK:~/Git/tetrate/tetrate-service-bridge-sandbox (delete-confirm) $ make destroy interactive=true Do you really want to destroy (y/n)? Destroy canceled. boeboe@Boeboe-NUC-WORK:~/Git/tetrate/tetrate-service-bridge-sandbox (delete-confirm) $ make destroy interactive=false dry_run=true Destroying without confirmation (interactive=false) make[1]: Entering directory '/home/boeboe/Git/tetrate/tetrate-service-bridge-sandbox' Destroy TSB Management Plane FQDN... JSON structure of 'terraform.tfvars.json' is valid. Going to destroy tsb management plane fqdn jq: error: Could not open file outputs/terraform_outputs/terraform-tsb-mp.json: No such file or directory Going to destroy tsb management plane fqdn on cloud 'azure' pushd tsb/fqdn/azure > /dev/null terraform workspace select default ... ``` ![Screenshot from 2023-10-25 07-13-04](https://github.com/tetrateio/tetrate-service-bridge-sandbox/assets/415310/c83edf87-6a1c-45c6-9bc8-073aeee0ad40)
1 parent 63aa7f6 commit fd3a7d2

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

Makefile

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Environment configuration
44
dry_run ?= false
5+
interactive ?= true
56
tfvars_json ?= terraform.tfvars.json
67
tf_log ?= "ERROR"
78

@@ -70,13 +71,31 @@ destroy_external_dns_%:
7071
@/bin/sh -c 'export DRY_RUN="${dry_run}" TF_LOG="${tf_log}" TFVARS_JSON="${tfvars_json}" && ./make/addon.sh destroy_external_dns_$*'
7172

7273
.PHONY: destroy
73-
destroy: destroy_remote destroy_local ## Destroy environment and local terraform state, cache and output artifacts
74+
destroy: confirm_destroy ## Destroy environment and local terraform state, cache and output artifacts
75+
76+
.PHONY: confirm_destroy
77+
confirm_destroy:
78+
ifeq ($(interactive),false)
79+
@echo "\033[1;31mDestroying without confirmation (interactive=false) \033[0m"
80+
@$(MAKE) actual_destroy
81+
else
82+
@echo -n "\033[1;31mDo you really want to destroy (y/n)? \033[0m" # Bold red text
83+
@read -p "" choice; \
84+
if [ "$${choice}" = "y" ] || [ "$${choice}" = "Y" ] || [ "$${choice}" = "yes" ] || [ "$${choice}" = "YES" ]; then \
85+
$(MAKE) actual_destroy; \
86+
else \
87+
echo "Destroy canceled."; \
88+
fi
89+
endif
90+
91+
.PHONY: actual_destroy
92+
actual_destroy: destroy_remote destroy_local
7493

7594
.PHONY: destroy_remote
7695
destroy_remote: ## Destroy environment
7796
@echo "Destroy TSB Management Plane FQDN..."
7897
@/bin/sh -c 'export DRY_RUN="${dry_run}" TF_LOG="${tf_log}" TFVARS_JSON="${tfvars_json}" && ./make/tsb.sh destroy_remote'
79-
@$(MAKE) destroy_external_dns
98+
# @$(MAKE) destroy_external_dns
8099
@$(MAKE) destroy_infra
81100

82101
.PHONY: destroy_local

0 commit comments

Comments
 (0)