Stack B needs the VPC ID created by stack A. Do you use `terraform_remote_state`, SSM parameters or a data source?
IntermediateScenarioModules and Code Structure
Answer
Situation read → Cross-stack data sharing, with different coupling levels.
What I'd do →
- Prefer data sources (
aws_vpcby tag) when the thing is discoverable. - Use SSM parameters or Secrets Manager as an explicit published contract between teams.
- Use
terraform_remote_stateonly inside one team where read access to the whole state is acceptable.
Why → terraform_remote_state exposes the entire state, including secrets, to the reader, and couples stacks to output names and the backend.
Interview tip → "Publish what you intend to share; don't share the whole state."
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