Module Reference Syntax
Git Source with Version
Always use version tags to ensure reproducible deployments:Branch Reference
For testing or development:Commit SHA Reference
For maximum stability:Common Patterns
Multi-Environment Setup
Organize modules across environments:Module Composition
Build complex infrastructure by composing modules:Using Module Outputs
Pass outputs between modules:Variable Management
Using terraform.tfvars
Store environment-specific values:Using Variable Files
Load different configurations:Environment Variables
Use TF_VAR prefix:State Management
Remote State Backend
Always use remote state for team collaboration:State Isolation
Isolate state by layer or component:Remote State Data Source
Reference outputs from other state files:Tagging Strategy
Consistent Tags Across Modules
Provider-Level Default Tags
Testing Modules
Plan Before Apply
Always review changes:Target Specific Modules
Test individual modules:Validate Configuration
Module Updates
Upgrading Module Versions
-
Review changelog:
-
Update source version:
-
Re-initialize:
-
Plan and review:
-
Apply changes:
Pinning Versions in CI/CD
Best Practices
Version Pinning
Always pin module versions using Git tags. Never use branches in production.
State Locking
Use DynamoDB for state locking to prevent concurrent modifications.
Environment Isolation
Separate state files and AWS accounts per environment.
Least Privilege IAM
Grant minimum required permissions. Use IAM roles over access keys.
Module Documentation
Document your usage patterns and custom configurations.
Change Review
Always review terraform plan output before applying.
Troubleshooting
Module Not Found
Error:State Lock Errors
Error:Module Output Not Available
Error:Related Documentation
VPC Module
Complete VPC infrastructure
EKS Module
Kubernetes cluster setup
State Module
Remote state backend
Infrastructure Guide
Complete deployment workflow