Modules Guide
September 29, 2025 Β· View on GitHub
This guide explains how to use and create modules in this repository, along with a complete catalog of available modules.
π¦ Complete Module Catalog
AWS Infrastructure Modules
π AWS VPC
- Path:
modules/aws-vpc/ - Description: Complete wrapper around terraform-aws-modules/vpc/aws with strong defaults
- Features:
- Multi-AZ subnets (public, private, database)
- NAT Gateway, Internet Gateway, Route tables
- VPC Flow Logs, DNS configuration
- SSM parameter storage for outputs
- Complete customization support
- Use Cases: Network foundation, multi-AZ setup, isolated environments
- Example Cost: ~$45/month (with NAT Gateway)
- Module Version: terraform-aws-modules/vpc/aws v5.21.0
Simple Usage:
module "vpc" {
source = "../../modules/aws-vpc"
name = "my-vpc"
tags = {
Environment = "production"
}
}
Advanced Usage:
module "vpc" {
source = "../../modules/aws-vpc"
name = "my-vpc"
tags = { Environment = "production" }
# Full customization available
cidr = "172.16.0.0/16"
enable_nat_gateway = true
single_nat_gateway = false
enable_flow_log = true
public_subnets = ["172.16.1.0/24", "172.16.2.0/24"]
private_subnets = ["172.16.11.0/24", "172.16.12.0/24"]
database_subnets = ["172.16.21.0/24", "172.16.22.0/24"]
}
β‘ AWS EKS
- Path:
modules/aws-eks/ - Description: Managed Kubernetes with essential addons
- Features: Cluster setup, node groups, IRSA, CNI configuration
- Use Cases: Microservices, container orchestration, modern applications
- Example Cost: ~$73/month (cluster) + worker nodes
ποΈ AWS RDS
- Path:
modules/aws-rds/ - Description: Complete wrapper around terraform-aws-modules/rds/aws with strong defaults
- Features:
- Multi-AZ, automated backups, monitoring
- Performance Insights, CloudWatch logs
- Encryption, parameter groups, option groups
- SSM parameter storage for connection info
- Complete customization support
- Use Cases: Application databases, data persistence, OLTP workloads
- Example Cost: ~$15-200/month (depending on instance size)
- Module Version: terraform-aws-modules/rds/aws v6.11.0
Simple Usage:
module "rds" {
source = "../../modules/aws-rds"
name = "my-app-db"
tags = { Environment = "production" }
engine = "postgres"
engine_version = "16.3"
instance_class = "db.t4g.micro"
vpc_security_group_ids = [aws_security_group.rds.id]
db_subnet_group_name = module.vpc.database_subnet_group
}
Advanced Usage:
module "rds" {
source = "../../modules/aws-rds"
name = "my-production-db"
tags = { Environment = "production" }
# Full customization available
engine = "postgres"
engine_version = "16.3"
instance_class = "db.r6g.large"
allocated_storage = 100
max_allocated_storage = 1000
multi_az = true
performance_insights_enabled = true
monitoring_interval = 60
backup_retention_period = 14
}
ποΈ AWS RDS Aurora
- Path:
modules/aws-rds-aurora/ - Description: High-performance Aurora cluster
- Features: Serverless options, global database, read replicas
- Use Cases: High-availability databases, read-heavy workloads, global apps
- Example Cost: ~$25-500/month (depending on configuration)
π¨ AWS MSK
- Path:
modules/aws-msk/ - Description: Managed Apache Kafka streaming
- Features: Multi-AZ clusters, monitoring, security configurations
- Use Cases: Event streaming, data pipelines, real-time analytics
- Example Cost: ~$180/month (3-broker cluster)
π° AWS Bastion
- Path:
modules/aws-bastion/ - Description: Secure jump host with SSM
- Features: SSM Session Manager, security groups, key management
- Use Cases: Secure access, troubleshooting, compliance requirements
- Example Cost: ~$8/month (t3.micro)
π AWS DocumentDB
- Path:
modules/aws-docdb/ - Description: MongoDB-compatible database
- Features: Cluster setup, backup, monitoring, security
- Use Cases: Document storage, NoSQL applications, MongoDB migration
- Example Cost: ~$55/month (basic cluster)
π€ AWS IAM Role
- Path:
modules/aws-iam-role/ - Description: IAM roles with best practices
- Features: Assume role policies, permission boundaries, trust relationships
- Use Cases: Service permissions, access control, IRSA
- Example Cost: Free (AWS IAM has no charges)
π AWS Amplify App
- Path:
modules/aws-amplify-app/ - Description: Frontend hosting and CI/CD
- Features: Git-based deployments, custom domains, branch-based environments
- Use Cases: Static sites, SPAs, JAMstack applications
- Example Cost: ~$1-15/month (depending on usage)
Other Cloud Providers
π MongoDB Atlas Cluster
- Path:
modules/mongodb-atlas-cluster/ - Description: Managed MongoDB in the cloud
- Features: Multi-cloud support, backup, monitoring, scaling
- Use Cases: Global databases, serverless apps, MongoDB-as-a-Service
- Example Cost: ~$57/month (M10 cluster)
π Security, Encryption & Governance Modules (Additional)
π AWS CloudTrail
- Path:
modules/aws-cloudtrail/ - Description: Configures account / organization-wide logging.
- Use Cases: Audit trails, compliance evidence, security incident investigation.
π‘οΈ AWS Config
- Path:
modules/aws-config/ - Description: Tracks resource configuration history and evaluates rules.
- Use Cases: Governance, drift detection, compliance frameworks (CIS, HIPAA).
π AWS GitHub OIDC Provider
- Path:
modules/aws-github-oidc-provider/ - Description: Federated identity provider for GitHub Actions (no static keys).
- Use Cases: Secure CI/CD deployments, least-privilege ephemeral credentials.
π§± Data Lake & Analytics Modules
π§± AWS Data Lake Infrastructure
- Path:
modules/aws-data-lake-infrastructure/ - Description: Creates medallion-zone S3 bucket structure (raw/bronze, processed/silver, curated/gold, temp) with optional lifecycle policies.
- Use Cases: Analytics landing zones, ETL staging, governed storage layout.
π AWS Data Lake Encryption
- Path:
modules/aws-data-lake-encryption/ - Description: Centralized KMS keys (S3 + Glue) for secure data operations.
- Use Cases: Multi-account encryption, central key rotation, compliance.
𧬠AWS Glue Code Registry
- Path:
modules/aws-glue-code-registry/ - Description: Manages Glue Schema / code registries for versioned serialization.
- Use Cases: Schema governance, event-driven ETL, compatibility tracking.
π AWS Glue Data Lake Catalog
- Path:
modules/aws-glue-data-lake-catalog/ - Description: Scaffolds Glue databases and tables for structured zones.
- Use Cases: Metadata discovery, unified data cataloging.
π οΈ AWS Glue Jobs
- Path:
modules/aws-glue-jobs/ - Description: Wrapper for defining multiple Glue Spark jobs via a map (complete wrapper + command enforcement).
- Use Cases: Batch ETL, transformations, enrichment pipelines.
π AWS Glue Workflow
- Path:
modules/aws-glue-workflow/ - Description: Orchestrates Glue jobs with triggers (scheduled / dependency).
- Use Cases: Chained ETL pipelines, periodic processing, SLA alignment.
π°οΈ Networking & Shared Services
βοΈ AWS Transit Gateway
- Path:
modules/aws-transit-gateway/ - Description: Central routing hub for multi-VPC / multi-account architectures.
- Use Cases: Hub-and-spoke networking, segmentation, centralized egress.
π°οΈ AWS Transit Gateway Spoke
- Path:
modules/aws-transit-gateway-spoke/ - Description: Attaches workload VPCs to a Transit Gateway.
- Use Cases: Network expansion, environment isolation.
πΈοΈ AWS Shared Networking
- Path:
modules/aws-shared-networking/ - Description: Shared services networking baseline (e.g., endpoints, DNS - depending on implementation).
- Use Cases: Centralized networking services account.
π¦ AWS TF State Backend
- Path:
modules/aws-tfstate-backend/ - Description: Provisions S3 bucket + DynamoDB table for remote Terraform state locking.
- Use Cases: Team collaboration, drift prevention, CI automation.
π§© Multi-Account Pattern Reference
The repository includes a simulated multi-account example: examples/multi-account-data-platform.
Key concepts demonstrated:
- Provider aliases standing in for account boundaries (
aws.infrastructure,aws.workloads_dev, future staging/prod commented) - Centralized encryption using
aws-data-lake-encryptionwith downstream sharing of key ARNs - Hub-and-spoke networking with
aws-transit-gateway+aws-transit-gateway-spoke - Data lake provisioning + Glue jobs + scheduled workflow orchestration
- Progressive environment expansion pattern (commented blocks for staging/prod)
For production evolution:
- Replace aliases with real
assume_roleprovider blocks per account - Add explicit KMS grants referencing workload account principals
- Externalize state (one backend per account; pass TGW + key ARNs via remote state or SSM)
- Harden networking (CIDR isolation, DNS resolver endpoints, security account logging aggregation)
Refer to the example README for full architecture notes.
Using Modules
Basic Usage
To use a module from this repository, add it to your Terraform configuration:
module "vpc" {
source = "github.com/nanlabs/terraform-aws-modules//modules/aws-vpc"
vpc_cidr = "10.0.0.0/16"
# ... other variables
}
Versioning
Always specify a version when using modules:
module "vpc" {
source = "github.com/nanlabs/terraform-aws-modules//modules/aws-vpc"
version = "1.0.0" # Use semantic versioning
# ... variables
}
Examples
Each module includes example configurations in its examples/ directory. These examples demonstrate common use cases and best practices.
Creating Modules
Module Structure
Each module must follow this structure:
modules/your-module/
βββ main.tf # Main resource definitions
βββ variables.tf # Input variables
βββ outputs.tf # Output values
βββ versions.tf # Version constraints
βββ README.md # Documentation
βββ examples/ # Example configurations
β βββ basic/
β βββ main.tf
β βββ variables.tf
β βββ outputs.tf
βββ docs/ # Additional documentation
βββ MODULE.md # Auto-generated docs
Using the Template
-
Copy the
modules/__template__directory to create a new module:cp -r modules/__template__ modules/your-module -
Update the following files:
main.tf: Define your resourcesvariables.tf: Define input variablesoutputs.tf: Define output valuesversions.tf: Set version constraintsREADME.md: Update documentation
-
Create at least one example in the
examples/directory
Best Practices
-
Input Variables
- Use descriptive names
- Provide default values when appropriate
- Include type constraints
- Add descriptions for all variables
-
Outputs
- Output all useful attributes
- Use consistent naming
- Include descriptions
-
Documentation
- Keep README.md up to date
- Document all variables and outputs
- Include usage examples
- Reference terraform-docs
-
Testing
- Include working examples
- Test with different configurations
- Validate security settings
Module Development Workflow
- Create a new branch for your module
- Copy the template directory
- Implement the module
- Add examples
- Generate documentation
- Test the module
- Create a pull request
Documentation
Use terraform-docs to generate documentation:
terraform-docs markdown . > docs/MODULE.md
The documentation should include:
- Module description
- Requirements
- Providers
- Inputs
- Outputs
- Examples