Skip to main content

CLI tool to scaffold production-ready Terraform modules with best practices

Project description

tf-module-scaffolder

Generate production-ready Terraform modules in seconds

CI Python 3.9+ MIT License


Overview

tf-module-scaffolder is a CLI tool that generates best-practice Terraform module structures with a single command. It creates complete, production-ready module scaffolds with proper file layout, documentation, CI/CD pipelines, linting configuration, and example code — all following HashiCorp and community conventions.

Why?

Starting a new Terraform module involves creating 10-15+ files with boilerplate and best practices. This tool does it in seconds while ensuring consistency across your module library.

Features

  • Multi-Cloud Support — AWS, Azure, and GCP module templates
  • 16 Module Templates — Pre-built for VPC, S3, VNet, Storage Account, GCS, and more
  • Production-Ready Structuremain.tf, variables.tf, outputs.tf, versions.tf, provider.tf
  • Variable Validation — Built-in validation rules for common patterns (CIDR, naming, etc.)
  • CI/CD Pipeline — GitHub Actions workflow for terraform validate + tflint
  • Pre-commit Hooksterraform fmt, validate, tflint, terraform-docs
  • TFLint Configuration — Provider-specific linting rules out of the box
  • Example Code — Ready-to-use example configurations
  • Test Scaffolding — Terratest structure for module testing
  • Beautiful CLI — Rich terminal output with file tree visualization
  • Three Modes — Interactive wizard, CLI flags, or quickstart presets

Installation

# Clone the repository
git clone https://github.com/SanjaySundarMurthy/tf-module-scaffolder.git
cd tf-module-scaffolder

# Install in development mode
pip install -e ".[dev]"

Quick Start

Quickstart Presets

# Scaffold an AWS VPC module
tf-scaffold quickstart aws-vpc

# Scaffold an Azure Storage Account module
tf-scaffold quickstart azure-storage

# Scaffold a GCP VPC module with custom name
tf-scaffold quickstart gcp-vpc -n my-network

Non-Interactive Mode

# AWS S3 bucket module
tf-scaffold new -p aws -t s3-bucket -n my-s3-module

# Azure VNet module with custom options
tf-scaffold new -p azure -t vnet -n my-vnet -d "Production VNet" -a "Platform Team"

# GCP module with minimal scaffold
tf-scaffold new -p gcp -t gcs-bucket -n my-bucket --no-ci --no-precommit

Interactive Mode

tf-scaffold new

This launches an interactive wizard that guides you through:

  1. Selecting a cloud provider (AWS / Azure / GCP)
  2. Choosing a module template
  3. Naming your module
  4. Generating the complete file structure

Available Templates

AWS

Template Description
vpc VPC with public/private subnets, NAT Gateway, and flow logs
s3-bucket S3 bucket with versioning, encryption, and lifecycle rules
eks-cluster EKS cluster with managed node groups
lambda-function Lambda function with IAM role and CloudWatch
rds-instance RDS instance with parameter groups and subnet groups

Azure

Template Description
resource-group Resource group with management lock
vnet Virtual network with subnets and NSGs
aks-cluster AKS cluster with node pools
storage-account Storage account with containers and lifecycle
app-service App Service with plan and deployment slots

GCP

Template Description
gcp-vpc VPC network with subnets, Cloud NAT, and firewall
gke-cluster GKE cluster with node pools
gcs-bucket Cloud Storage bucket with lifecycle and IAM
cloud-run Cloud Run service with IAM
cloud-sql Cloud SQL instance with databases

Generated Structure

terraform-aws-vpc/
├── main.tf                    # Core resources
├── variables.tf               # Input variable definitions
├── outputs.tf                 # Output value definitions
├── versions.tf                # Terraform & provider version constraints
├── provider.tf                # Provider configuration
├── README.md                  # Module documentation
├── Makefile                   # Common Terraform commands
├── .gitignore                 # Terraform-specific ignores
├── .tflint.hcl                # TFLint configuration
├── .pre-commit-config.yaml    # Pre-commit hooks
├── .github/
│   └── workflows/
│       └── ci.yml             # GitHub Actions CI/CD
├── examples/
│   └── basic/
│       └── main.tf            # Example usage
└── tests/
    └── main.tf                # Test configuration

CLI Reference

Usage: tf-scaffold [OPTIONS] COMMAND [ARGS]...

Commands:
  list        List available module templates
  new         Scaffold a new Terraform module
  quickstart  Quick-scaffold a module from a preset

Options:
  --version  Show the version and exit
  --help     Show this message and exit

tf-scaffold new Options

Option Description
-p, --provider Cloud provider: aws, azure, gcp
-t, --template Module template name
-n, --name Module name
-o, --output-dir Output directory (default: current)
-d, --description Module description
-a, --author Author name
--no-examples Skip examples directory
--no-tests Skip tests directory
--no-ci Skip CI workflow
--no-precommit Skip pre-commit config
--no-makefile Skip Makefile

Development

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest -v

# Lint
ruff check .

# Format check
ruff format --check .

Architecture

tf_module_scaffolder/
├── models.py            # Data models (Provider, ModuleType, Config)
├── engine.py            # Scaffold engine (file generation)
├── cli.py               # Click CLI commands
├── templates/
│   ├── hcl.py           # Jinja2 HCL templates
│   └── definitions.py   # Variable/output definitions
└── output/
    └── console.py       # Rich console rendering

Author

Sanjay S — Senior DevOps Engineer
GitHub · Portfolio

License

MIT License — see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tf_module_scaffolder-1.0.0.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tf_module_scaffolder-1.0.0-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file tf_module_scaffolder-1.0.0.tar.gz.

File metadata

  • Download URL: tf_module_scaffolder-1.0.0.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for tf_module_scaffolder-1.0.0.tar.gz
Algorithm Hash digest
SHA256 994fa37c3fade5af0a1a9066aa0bd310362be890d124efe0b5576426500589b1
MD5 8cda24e3c631cbbd108cc2d95392fb87
BLAKE2b-256 c9b2002b98b9f894fe7721e17bcad64bf5383ee4edbed81c530e58ba36ba0c90

See more details on using hashes here.

File details

Details for the file tf_module_scaffolder-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tf_module_scaffolder-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c3977c80e800f637540262915c0cafe287b86beba3750153172240ff40a8aaf
MD5 4ba82d5ec9860f8d135abe89927e9e6f
BLAKE2b-256 24d97dd9b69411402e88a0cbf5b85b1ba4dcf477b300c6ba311681d54f7cbe97

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page