Makefile

Complete reference for Makefile commands in the AWS Terraform Starter Kit.


Overview

The Makefile provides a unified interface for managing the Terraform Starter Kit lifecycle, from initial setup to daily operations. It wraps Terraform commands with validation, error handling, and environment management.

Quick reference

CommandDescription
make helpDisplay all available commands
make setupComplete setup wizard
make install-toolsInstall required development tools
make checkCheck installed tool versions
make validate-fullRun all validation checks
make validate-env ENV=xValidate specific environment
make formatFormat Terraform files
make lintRun TFLint checks
make security-scanRun Checkov security scan
make init ENV=<env>Initialize Terraform for an environment
make plan ENV=<env>Create Terraform plan
make apply ENV=<env>Apply Terraform changes
make destroy ENV=<env>Destroy Terraform resources
make cleanupInteractive cleanup script

Setup commands

make setup

Run the complete setup wizard that bootstraps infrastructure, provisions environments, and deploys OIDC configuration.

What it does:

  1. Checks prerequisites (AWS CLI, Terraform, Git)
  2. Verifies AWS credentials
  3. Creates S3 backend with native state locking
  4. Provisions environment directories and workflows
  5. Deploys OIDC provider and IAM roles

Usage:

make setup                              # Interactive setup
./scripts/setup.sh -e test,staging -a   # Auto-approve
./scripts/setup.sh --skip-bootstrap     # Use existing backend

Script options:

OptionDescription
-e, --environments ENV1,ENV2Comma-separated list of environments
-p, --profile PROFILEAWS profile to use
-a, --auto-approveSkip interactive confirmations
-s, --skip-bootstrapSkip bootstrap step
-d, --skip-deploySkip OIDC deployment

make install-tools

Install required and optional development tools.

ToolStatusPurpose
TerraformRequiredInfrastructure as code
AWS CLIRequiredAWS command-line interface
TFLintOptionalTerraform linter
CheckovOptionalSecurity scanner
GrantedOptionalAWS profile manager
make install-tools

Validation commands

make validate-full

Run comprehensive validation across all environments.

StepDescription
FormattingVerifies Terraform file formatting
ValidationValidates Terraform syntax
TFLintRuns linting checks
CheckovPerforms security analysis
make validate-full

make validate-env

Validate Terraform configuration for a specific environment.

make validate-env ENV=staging
make validate-env ENV=staging ARGS="-json"

make lint

Run TFLint checks across all Terraform files.

make lint

make security-scan

Run Checkov security scan on Terraform code.

make security-scan

make format

Format all Terraform files recursively.

make format

Deployment commands

All deployment commands require the ENV parameter.

make init

Initialize Terraform backend for an environment.

make init ENV=staging
make init ENV=staging ARGS="-upgrade"
make init ENV=staging ARGS="-reconfigure"

make plan

Create a Terraform execution plan.

make plan ENV=staging
make plan ENV=staging ARGS="-out=tfplan"
make plan ENV=staging ARGS="-target=module.oidc_provider"

make apply

Apply Terraform changes.

make apply ENV=staging
make apply ENV=staging ARGS="-auto-approve"
make apply ENV=staging ARGS="tfplan"

Warning: Use -auto-approve carefully in production.

make destroy

Destroy Terraform-managed infrastructure.

make destroy ENV=test
make destroy ENV=staging ARGS="-auto-approve"
make destroy ENV=staging ARGS="-target=module.oidc_provider"

Utility commands

make cleanup

Interactive cleanup script with options:

OptionDescription
Destroy environment resourcesRemoves OIDC providers, IAM roles
Destroy bootstrap resourcesRemoves S3 bucket
Clean local filesRemoves .terraform/, lock files
Remove source filesDeletes environment directories
Full cleanupAll of the above
make cleanup

make check

Check versions of all required and optional tools.

make check

Environment variables

VariableDescriptionExample
ENVTarget environmentENV=staging
ARGSAdditional Terraform argumentsARGS="-auto-approve"
AWS_PROFILEAWS profile to useAWS_PROFILE=staging
AWS_REGIONAWS regionAWS_REGION=us-east-1

Common workflows

Initial setup

make install-tools
make setup
make check

Development workflow

make validate-full
make format
make init ENV=staging
make plan ENV=staging
make apply ENV=staging

Multi-environment deployment

# Test
make plan ENV=test && make apply ENV=test

# Staging
make plan ENV=staging && make apply ENV=staging

# Production (with saved plan)
make plan ENV=production ARGS="-out=tfplan"
make apply ENV=production ARGS="tfplan"

Error handling

Missing ENV parameter

$ make plan
❌ Error: ENV variable is required
Usage: make plan ENV=staging

Invalid environment

$ make plan ENV=nonexistent
❌ Error: Environment 'nonexistent' does not exist

Missing tools

$ make lint
TFLint not installed. Run 'make install-tools' to install.

Troubleshooting

State lock issues

cd environments/staging
terraform force-unlock <LOCK_ID>

Backend configuration issues

cat .terraform-backend.conf
aws s3 ls s3://terraform-state-ACCOUNT-REGION
make init ENV=staging ARGS="-reconfigure"

Permission errors

aws sts get-caller-identity
assume staging-account

Next steps