简体   繁体   English

如何将 Object 属性从我的父母传递给 Terraform 中的孩子?

[英]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.

相关问题 如何将应用服务名称从我的 terraform 部署传递到 devops 中的应用服务部署? - How do I pass the app service name from my terraform deployment to an app service deployment in devops? 使用 Terraform,如何将用户列表从一个模块传递到另一个模块 - Using Terraform, how can I pass in a list of users from module to module 如何将变量传递给 XML 文件(通过 Terraform)? - How can I pass in a variable to an XML file (via Terraform)? 如何更正 Terraform,错误:不正确的属性值类型错误? - How can I correct a Terraform, Error: Incorrect attribute value type error? Terraform,如何将数据从一个子模块传递到另一个 - Terraform, how to pass data from one child module to another 如何传递 Terraform output 中的值而不将其放入 tfvars 文件中 - How to pass values from the Terraform output without putting it in the tfvars file 如何将 Terraform 中的逻辑用于 Azure? - How can i use logic in Terraform for Azure? 如何让 `terraform init` 在我的 Apple Silicon Macbook Pro 上为 Google Provider 运行? - How can I get `terraform init` to run on my Apple Silicon Macbook Pro for the Google Provider? 我怎样才能 terraform 授予访问我的 Azure Active Directory 租户 - How can I terraform granting access to my Azure Active Directory Tenant 如何在我的 Terraform 项目中重新使用配置(本地模块)? - How can I re-use a configuration (local module) with my Terraform project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM