Where do you put provider-agnostic helper logic, such as naming and tagging conventions, shared by all stacks?
IntermediateScenarioModules and Code Structure
Answer
Situation read → Naming logic is copy-pasted in every stack.
What I'd do → Create a tiny "context" or "naming" module with no resources, just locals and outputs.
module "ctx" {
source = "git::https://github.com/acme/tf-modules.git//context?ref=v1.2.0"
project = "payments"
environment = var.environment
}
resource "aws_s3_bucket" "x" {
bucket = "${module.ctx.prefix}-reports"
tags = module.ctx.tags
}
Why → One definition of "how we name things" means a convention change is a single release.
Interview tip → Keep it dumb and stable; it's imported everywhere.
More on Modules and Code Structure
When do you turn a block of resources into a module, and when do you leave it alone?BeginnerHow do you consume a community module like `terraform-aws-modules/vpc/aws` responsibly?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?Advanced