Terraform模块variablesinheritance

我正在尝试使terraform的一些模块尽可能简单,但似乎没有其他方法来做我想要实现的:

main.tf我有这个:

module "vpc" { source = "git::ssh://[email protected]/vpc.git" env = "test" } module "ec2" { source = "ec2/" env = "test" subnets = "${module.vpc.subnets}" } 

ec2 / main.tf中

 module "instance01" { source = "git::ssh://[email protected]/ec2.git" env = "test" subnets = "${var.subnets}" name = "instance01" } module "instance02" { source = "git::ssh://[email protected]/ec2.git" env = "test" subnets = "${var.subnets}" name = "instance02" } 

有什么办法可以inheritance子网,所以我不必显式地将其添加到此模块的每个资源定义中? 就像是:

 module "instance01" { source = "git::ssh://[email protected]/ec2.git" name = "instance01" } module "instance02" { source = "git::ssh://[email protected]/ec2.git" name = "instance02" } 

当然子网只有1个variables需要反复传递,实际上这个模块有5或6个variables,我只是把它们粘贴到每个资源上。

我希望Terraform将提供的是,如果我在模块中定义variables,它是inheritance给所有的孩子。