[英]How can I pass an Object Attribute from my parent to a children in Terraform?
I want to pass for example the ID of a VPC, which lives in the parent, to a Module in Terraform. I already figured out that I can do so by using the Outputs.tf
, initialize a variable in the variables.tf
in the children and value it in the "module" in the parents main.tf
.例如,我想将位于父级中的 VPC 的 ID 传递给 Terraform 中的模块。我已经发现我可以通过使用
Outputs.tf
来实现,在variables.tf
中初始化变量孩子并在父母main.tf
的“模块”中重视它。 If you would do the same the other way, you'd just have to say for example如果你用另一种方式做同样的事情,你只需要说例如
module "example"{
vpc_id = module.network.vpc.id
}
But as I need it the other way around, I can't say module.network.但是因为我反过来需要它,所以我不能说 module.network。 How would I have to do this, when I#m referring to an Object of the Parent?
当我指的是父母的 Object 时,我该怎么办?
Let's say your VPC is named "main" like in the official examples .假设您的 VPC 在官方示例中被命名为“main”。
To reference the ID anywhere in the parent Terraform template, you would use aws_vpc.main.id
.要在父 Terraform 模板中的任何位置引用 ID,您可以使用
aws_vpc.main.id
。
So to pass that to a module, it would look like this;所以要将其传递给模块,它看起来像这样;
module "example"{
vpc_id = aws_vpc.main.id
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.