How do you consume a community module like `terraform-aws-modules/vpc/aws` responsibly?
BeginnerScenarioModules and Code Structure
Answer
Situation read → Public modules save weeks, but they are third-party code running with your credentials.
What I'd do →
- Pin the version with a constraint.
- Read the module source and its resources before adopting.
- Review the plan on every version bump.
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 5.0"
name = "prod"
cidr = "10.0.0.0/16"
}
Why → Unpinned modules change under you. Pinning plus plan review treats module upgrades like any other dependency.
Interview tip → Many companies wrap popular modules in an internal one to enforce tags and encryption.
More on Modules and Code Structure
When do you turn a block of resources into a module, and when do you leave it alone?BeginnerAn ECS service module needs the VPC and subnets created by a network module. How do you wire them together?IntermediateHow would you lay out a repo that deploys the same stack to dev, stage and prod?IntermediateHow do you release a shared module so consumers can upgrade at their own pace?IntermediateA module needs to deploy to a second region. Why does putting a provider block inside the module cause trouble?AdvancedTeams complain a "VPC module" has 90 variables and still doesn't do what they need. How do you fix the design?Intermediate