# Makefile for HAPI Terraform infrastructure .PHONY: init plan apply destroy output env # Environment defaults ENV ?= staging REGION ?= us-east OBJECT_STORAGE_CLUSTER ?= us-east-1 # Initialize Terraform init: @echo "Initializing Terraform..." terraform init # Initialize with backend configuration init-backend: @echo "Initializing Terraform with backend..." terraform init -reconfigure \ -backend-config=bucket=hapi-terraform-state-${ENV} \ -backend-config=key=terraform/${ENV}/terraform.tfstate \ -backend-config=region=${OBJECT_STORAGE_CLUSTER} # Generate plan plan: @echo "Generating Terraform plan for ${ENV}..." terraform plan -var="environment=${ENV}" -var="linode_object_storage_cluster=${OBJECT_STORAGE_CLUSTER}" # Apply changes apply: @echo "Applying Terraform changes for ${ENV}..." terraform apply -var="environment=${ENV}" -var="linode_object_storage_cluster=${OBJECT_STORAGE_CLUSTER}" # Apply with auto-approve apply-auto: @echo "Applying Terraform changes for ${ENV} (auto-approve)..." terraform apply -var="environment=${ENV}" -var="linode_object_storage_cluster=${OBJECT_STORAGE_CLUSTER}" -auto-approve # Destroy infrastructure destroy: @echo "Destroying Terraform infrastructure for ${ENV}..." terraform destroy -var="environment=${ENV}" -var="linode_object_storage_cluster=${OBJECT_STORAGE_CLUSTER}" # Show outputs output: @echo "Terraform outputs:" terraform output -json | jq -r 'to_entries | .[] | "\(.key) = \(.value.value)"' 2>/dev/null || terraform output # Load environment variables env: @echo "Environment variables:" @echo " ENV=${ENV}" @echo " REGION=${REGION}" @echo " OBJECT_STORAGE_CLUSTER=${OBJECT_STORAGE_CLUSTER}" @echo " LINODE_TOKEN=${LINODE_TOKEN}" @echo " OBJECT_STORAGE_ACCESS_KEY=${OBJECT_STORAGE_ACCESS_KEY}" @echo " OBJECT_STORAGE_SECRET_KEY=${OBJECT_STORAGE_SECRET_KEY}" # Run all checks check: init plan apply # Validate configuration validate: @echo "Validating Terraform configuration..." terraform validate # Clean up local state clean: @echo "Cleaning local Terraform files..." rm -rf .terraform/ rm -f .terraform.lock.hcl