繁体   English   中英

您如何使用 terraform 应用程序的 output 作为另一个 terraform 变量的输入?

[英]How do you use the output of a terraform apply as input into another terraform variable?

政策即代码 - Azure - Terraform https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/policy_definition

output 是一个 ID。 此 id 需要用作策略分配的变量。 https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group_policy_assignment

  1. terraform这个是怎么写的?
  2. terraform 申请是否需要为每个定义和分配分开?

看起来您只是从 Terraform 开始,但很容易将一个资源的 output 传递给另一个资源,Terraform 将确保在 resource_group_policy_Assignment 之前部署 policy_definition。

假设块的名称称为 policy,如 terraform 网站所示。 策略分配中对 ID 的引用类似于 - azurerm_policy_definition.policy.id

请阅读 terraform 中的文档以获取参考资源。 https://www.terraform.io/language/expressions/references#resources https://www.terraform.io/language/expressions/references#references-to-resource-attributes

您可以简单地将azurerm_policy_definition output 传递给资源azurerm_resource_group_policy_assignment就像您在DOC中找到的示例一样

resource "azurerm_resource_group_policy_assignment" "example" {
  name                 = "example"
  resource_group_id    = azurerm_resource_group.example.id
  policy_definition_id = azurerm_policy_definition.example.id # This is the output of azurerm_policy_definition resource

  ...
  ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM