@@ -19,6 +19,21 @@ INFRA_TESTS_DIR = infrastructure/tests
1919TESTS_DIR  = tests
2020SCRIPTS_DIR  = infrastructure/scripts
2121
22+ #  Parameter validation for infrastructure commands
23+ check-infra-params :
24+ 	@if [ -z  " $( ENVIRONMENT) "   ];  then  \ 
25+ 		echo  " ❌ Error: ENVIRONMENT not specified" ;  \ 
26+ 		echo  " Usage: make <target> ENVIRONMENT=<env> PROVIDER=<provider>" ;  \ 
27+ 		echo  " Available environments: development, staging, production" ;  \ 
28+ 		exit  1;  \ 
29+ 	fi 
30+ 	@if [ -z  " $( PROVIDER) "   ];  then  \ 
31+ 		echo  " ❌ Error: PROVIDER not specified" ;  \ 
32+ 		echo  " Usage: make <target> ENVIRONMENT=<env> PROVIDER=<provider>" ;  \ 
33+ 		echo  " Available providers: libvirt, hetzner" ;  \ 
34+ 		exit  1;  \ 
35+ 	fi 
36+ 
2237#  Help target
2338help : # # Show this help message
2439	@echo " Torrust Tracker Demo - Twelve-Factor App Deployment" 
@@ -63,15 +78,15 @@ install-deps: ## Install required dependencies (Ubuntu/Debian)
6378#  INFRASTRUCTURE LAYER (PLATFORM SETUP & CONFIGURATION)
6479#  =============================================================================
6580
66- infra-init : # # Initialize infrastructure (Terraform init)
81+ infra-init : check-infra-params  # # Initialize infrastructure (Terraform init)
6782	@echo " Initializing infrastructure for $( ENVIRONMENT)   on $( PROVIDER)  ..." 
6883	$(SCRIPTS_DIR ) /provision-infrastructure.sh $(ENVIRONMENT )  $(PROVIDER )  init
6984
70- infra-plan : # # Plan infrastructure changes
85+ infra-plan : check-infra-params  # # Plan infrastructure changes
7186	@echo " Planning infrastructure for $( ENVIRONMENT)   on $( PROVIDER)  ..." 
7287	$(SCRIPTS_DIR ) /provision-infrastructure.sh $(ENVIRONMENT )  $(PROVIDER )  plan
7388
74- infra-apply : # # Provision infrastructure (platform setup)
89+ infra-apply : check-infra-params  # # Provision infrastructure (platform setup)
7590	@echo " Provisioning infrastructure for $( ENVIRONMENT)   on $( PROVIDER)  ..." 
7691	@echo " ⚠️  This command may prompt for your password for sudo operations" 
7792	@if [ " $( SKIP_WAIT) "   =  " true"   ];  then  \ 
@@ -81,15 +96,15 @@ infra-apply: ## Provision infrastructure (platform setup)
8196	fi 
8297	SKIP_WAIT=$(SKIP_WAIT )  $(SCRIPTS_DIR ) /provision-infrastructure.sh $(ENVIRONMENT )  $(PROVIDER )  apply
8398
84- infra-destroy : # # Destroy infrastructure
99+ infra-destroy : check-infra-params  # # Destroy infrastructure
85100	@echo " Destroying infrastructure for $( ENVIRONMENT)   on $( PROVIDER)  ..." 
86101	$(SCRIPTS_DIR ) /provision-infrastructure.sh $(ENVIRONMENT )  $(PROVIDER )  destroy
87102
88- infra-status : # # Show infrastructure status
103+ infra-status : check-infra-params  # # Show infrastructure status
89104	@echo " Infrastructure status for $( ENVIRONMENT)   on $( PROVIDER)  :" 
90105	@cd $(TERRAFORM_DIR )  &&  tofu show -no-color |  grep -E " (vm_ip|vm_status)"   ||  echo  " No infrastructure found" 
91106
92- infra-refresh-state : # # Refresh Terraform state to detect IP changes
107+ infra-refresh-state : check-infra-params  # # Refresh Terraform state to detect IP changes
93108	@echo " Refreshing Terraform state..." 
94109	@cd $(TERRAFORM_DIR )  &&  tofu refresh
95110
0 commit comments