Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions Makefile.terraform
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
31 changes: 20 additions & 11 deletions scripts/tf-deploy.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash
# Terraform Deployment Helper Script
# Usage: ./scripts/tf-deploy.sh <provider> <profile> [action]
# Usage: ./scripts/tf-deploy.sh <provider> <profile> [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

Expand Down Expand Up @@ -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 <provider> <profile> [action]"
log_error "Usage: $0 <provider> <profile> [action] [extra terraform args...]"
echo ""
echo "Examples:"
echo " $0 aws dev # Deploy to AWS dev"
Expand Down Expand Up @@ -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

Expand Down
Loading