azure - 如何从azurerm_resource_group_template_deployment读取output_content

标签 azure terraform terraform-provider-azure

我定义了一个 azurerm_resource_group_template_deployment my_rm ,它具有 ARM 模板源:

{
  ...
  "parameters": {...  }, 
  "resources": [ ...  ],
  "outputs": {
    "db_name": {
      "type": "string",
      "value": "test_value"
    } 
  }
}

我想在 terraform 中使用此输出,例如:

output "db_name" {
  value = azurerm_resource_group_template_deployment.my_rm.output_content["db_name"]
}

不幸的是,上面的定义返回空值。

在 terraform 中定义输出的正确方法是什么?

最佳答案

output_content导出 ARM 模板部署输出的 JSON 内容

经过我的验证,你可以输出内容

output "db_name" {
  value = azurerm_resource_group_template_deployment.my_rm.output_content
}

然后运行terraform apply,您将看到输出结果,然后您可以更改为过滤结果

output "db_name" {
  value = jsondecode(azurerm_resource_group_template_deployment.my_rm.output_content).db_name.value
}

请注意,db_name 与 terraform 代码中的 db_name 声明不同,它实际上应该与上述第一个步骤中的输出 JSON 键匹配。

例如,

enter image description here

关于azure - 如何从azurerm_resource_group_template_deployment读取output_content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64360895/

相关文章:

azure - 为什么Azure存储帐户有两个 key ?

c# - DataCache 操作 - 验证成功

azure - 防止 Azure Webjobs 输出队列出现空队列消息

terraform - Terraform 数据源中获取的值与计算的值

azure - 在进行 Azure 应用程序注册时,Terraform 出现循环错误

Azure : GroupsClient. BaseClient.Get():意外状态 403,带有 OData 错误:Authorization_RequestDenied:权限不足

azure - 如何使用 Azure 事件网格传递到 GCP 的事件

cloud - terraform 中数据和导入之间的区别

terraform - 将 "Provider"和 "Terraform"版本存储在单独的 TF 文件中?

azure - 如何强制变量值采用特定模式