From 045fe636a897fc8fa767dd16cf3b42668de63615 Mon Sep 17 00:00:00 2001 From: Cristian Magherusan-Stanciu Date: Thu, 11 Jun 2026 01:30:43 -0700 Subject: [PATCH] fix(deploy): forward extra terraform args, drop vestigial targets The Makefile.terraform targets docker-build, docker-skip and frontend-skip passed -var flags as a 4th argument to tf-deploy.sh, which only consumed $1..$3, so the flags were silently discarded and each target ran a plain full terraform apply. The named variables (skip_docker_push, skip_docker_build, enable_frontend_build) are not declared root-module variables in any environment, so the targets were never functional; nothing references them. Remove them and their .PHONY entries instead of plumbing dead variables through three cloud roots. Fix the root cause in scripts/tf-deploy.sh so this argument class can never be silently dropped again: arguments after provider/profile/ action are now forwarded verbatim to terraform (set -u safe on bash 3.2 via the ${arr[@]+...} guard). Also make the usage check reachable: PROVIDER=$1 aborted with "unbound variable" under set -u before the intended usage message could print; use ${1:-}/${2:-} defaults. Verified with a stub terraform binary: extra -var/-target args now appear in the rendered command line, plain invocations are unchanged, and the no-args usage path exits 1 with the usage text. make -n shows the removed targets now fail loudly with "No rule to make target". Closes #1172 --- Makefile.terraform | 15 +-------------- scripts/tf-deploy.sh | 31 ++++++++++++++++++++----------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/Makefile.terraform b/Makefile.terraform index 19668255b..fae7aff81 100644 --- a/Makefile.terraform +++ b/Makefile.terraform @@ -3,7 +3,7 @@ .PHONY: help deploy plan destroy profile-new profile-list profile-show clean clean-locks \ output aws-dev aws-prod azure-dev gcp-dev quick-plan aws-dev-plan quick-deploy \ - validate fmt state-list state-show docker-build docker-skip frontend-only frontend-skip + validate fmt state-list state-show frontend-only # Default profile settings PROVIDER ?= aws @@ -123,21 +123,8 @@ state-list: ## List resources in Terraform state state-show: ## Show detailed state for a resource @cd terraform/environments/$(PROVIDER)/$(PROFILE) && terraform state show $(RESOURCE) -# Docker operations -docker-build: ## Build Docker image only - @echo "🔨 Building Docker image..." - @./scripts/tf-deploy.sh $(PROVIDER) $(PROFILE) apply -var="skip_docker_push=true" - -docker-skip: ## Deploy without Docker build - @echo "⏭️ Deploying without Docker build..." - @./scripts/tf-deploy.sh $(PROVIDER) $(PROFILE) apply -var="skip_docker_build=true" - # Frontend operations frontend-only: ## Deploy frontend only @echo "🎨 Deploying frontend..." @cd terraform/environments/$(PROVIDER)/$(PROFILE) && \ terraform apply -var-file="../../../profiles/$(PROVIDER)/$(PROFILE).tfvars" -target=module.frontend - -frontend-skip: ## Deploy without frontend - @echo "⏭️ Deploying without frontend..." - @./scripts/tf-deploy.sh $(PROVIDER) $(PROFILE) apply -var="enable_frontend_build=false" diff --git a/scripts/tf-deploy.sh b/scripts/tf-deploy.sh index 0de1aa0e0..28d7fd44a 100755 --- a/scripts/tf-deploy.sh +++ b/scripts/tf-deploy.sh @@ -1,8 +1,9 @@ #!/bin/bash # Terraform Deployment Helper Script -# Usage: ./scripts/tf-deploy.sh [action] +# Usage: ./scripts/tf-deploy.sh [action] [extra terraform args...] # Example: ./scripts/tf-deploy.sh aws dev # Example: ./scripts/tf-deploy.sh aws prod plan +# Example: ./scripts/tf-deploy.sh aws dev apply -target=module.frontend set -euo pipefail @@ -31,12 +32,18 @@ log_error() { } # Parse arguments -PROVIDER=$1 -PROFILE=$2 +PROVIDER=${1:-} +PROFILE=${2:-} ACTION=${3:-apply} +# Any further arguments are forwarded verbatim to terraform (e.g. -target=...). +EXTRA_ARGS=() +if [ "$#" -gt 3 ]; then + EXTRA_ARGS=("${@:4}") +fi + if [ -z "$PROVIDER" ] || [ -z "$PROFILE" ]; then - log_error "Usage: $0 [action]" + log_error "Usage: $0 [action] [extra terraform args...]" echo "" echo "Examples:" echo " $0 aws dev # Deploy to AWS dev" @@ -112,34 +119,36 @@ fi log_info "Running terraform ${ACTION}..." echo "" +# ${EXTRA_ARGS[@]+...} keeps the empty-array expansion safe under set -u +# on bash 3.2 (macOS default). case $ACTION in plan) - terraform plan -var-file="$PROFILE_FILE" + terraform plan -var-file="$PROFILE_FILE" ${EXTRA_ARGS[@]+"${EXTRA_ARGS[@]}"} ;; apply) - terraform apply -var-file="$PROFILE_FILE" + terraform apply -var-file="$PROFILE_FILE" ${EXTRA_ARGS[@]+"${EXTRA_ARGS[@]}"} ;; destroy) log_warning "This will destroy all resources!" read -p "Are you sure? (type 'yes' to confirm): " confirm if [ "$confirm" = "yes" ]; then - terraform destroy -var-file="$PROFILE_FILE" + terraform destroy -var-file="$PROFILE_FILE" ${EXTRA_ARGS[@]+"${EXTRA_ARGS[@]}"} else log_info "Destroy cancelled" exit 0 fi ;; show) - terraform show + terraform show ${EXTRA_ARGS[@]+"${EXTRA_ARGS[@]}"} ;; refresh) - terraform refresh -var-file="$PROFILE_FILE" + terraform refresh -var-file="$PROFILE_FILE" ${EXTRA_ARGS[@]+"${EXTRA_ARGS[@]}"} ;; output) - terraform output + terraform output ${EXTRA_ARGS[@]+"${EXTRA_ARGS[@]}"} ;; *) - terraform $ACTION -var-file="$PROFILE_FILE" + terraform "$ACTION" -var-file="$PROFILE_FILE" ${EXTRA_ARGS[@]+"${EXTRA_ARGS[@]}"} ;; esac