Using Module Outputs
The root module calls a child module with module "network" { source = "./modules/network" }. Inside it, the VPC is aws_vpc.main. How does the root module get the VPC ID?
module "network" { source = "./modules/network" }
aws_vpc.main
Choose one answer
Declare output "vpc_id" { value = aws_vpc.main.id } in the child module and reference module.network.vpc_id in the root.
output "vpc_id" { value = aws_vpc.main.id }
module.network.vpc_id
Reference aws_vpc.main.id directly from the root module.
aws_vpc.main.id
Declare variable "vpc_id" in the root; Terraform fills it from the child automatically.
variable "vpc_id"
Use data.module.network.vpc_id.
data.module.network.vpc_id