使用 terraform 输出恢复 Azure ARM 模板的输出值
Recover output value of Azure ARm template with terraform output
使用 terraform 和 Azure ARM 模板,为了使用特定的 azure 函数配置事件网格,我正在尝试恢复 terraform 输出中的一些值。
确实,我有这个 ARM 模板部署来获得特定功能的系统键:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"functionApp": {
"type": "string",
"defaultValue": ""
}
},
"variables": {
"functionAppId": "[resourceId('Microsoft.Web/sites', parameters('functionApp'))]"
},
"resources": [],
"outputs": {
"systemKeys": {
"type": "object",
"value": "[listkeys(concat(variables('functionAppId'), '/host/default'), '2018-11-01').systemKeys]"
}
}
}
我的部署运行良好,因为我可以在 Azure 门户中看到输出中有一个 json 对象,如下所示:
{
"durabletask_extension": "ASensituveValueIDoNotShareForDurableTaskExtension==",
"eventgrid_extension": "ASensituveValueIDoNotShareForEventGridExtension=="
}
现在的目的是在 terraform 输出中获取此值之一。
我尝试了这些,但出现了一些错误:
output "syst_key" {
value = "${azurerm_template_deployment.function_keys.outputs["systemKeys"]}"
}
Error: on outputs.tf line 69, in output "syst_key":
69: value = "${azurerm_template_deployment.function_keys.outputs["systemKeys"]}"
|----------------
| azurerm_template_deployment.function_keys.outputs is empty map of string
output "syst_keys" {
value = "${lookup(azurerm_template_deployment.function_keys.outputs, "systemKeys")}"
}
Error: on outputs.tf line 77, in output "syst_key":
77: value = "${lookup(azurerm_template_deployment.function_keys.outputs, "systemKeys")}"
|----------------
| azurerm_template_deployment.function_keys.outputs is empty map of string
Call to function "lookup" failed: lookup failed to find 'systemKeys'.
为了在此函数上触发事件网格,我必须从我的 ARM 部署模板中恢复 systemKeys 的 terraform 输出中的值。我知道部署运行良好,我只是不知道如何使用 terraform 恢复这些值。
对于您的问题,您需要注意只有类型 String、Int 和 Bool 在 Terraform 中受支持。所以你需要在模板中更改输出类型,然后你可以在 Terraform 中输出它们。有关详细信息,请参阅 outputs。 Terraform 中的正确输出如下:
output "syst_key" {
value = "${azurerm_template_deployment.function_keys.outputs["systemKeys"]}"
}
使用 terraform 和 Azure ARM 模板,为了使用特定的 azure 函数配置事件网格,我正在尝试恢复 terraform 输出中的一些值。
确实,我有这个 ARM 模板部署来获得特定功能的系统键:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"functionApp": {
"type": "string",
"defaultValue": ""
}
},
"variables": {
"functionAppId": "[resourceId('Microsoft.Web/sites', parameters('functionApp'))]"
},
"resources": [],
"outputs": {
"systemKeys": {
"type": "object",
"value": "[listkeys(concat(variables('functionAppId'), '/host/default'), '2018-11-01').systemKeys]"
}
}
}
我的部署运行良好,因为我可以在 Azure 门户中看到输出中有一个 json 对象,如下所示:
{
"durabletask_extension": "ASensituveValueIDoNotShareForDurableTaskExtension==",
"eventgrid_extension": "ASensituveValueIDoNotShareForEventGridExtension=="
}
现在的目的是在 terraform 输出中获取此值之一。 我尝试了这些,但出现了一些错误:
output "syst_key" {
value = "${azurerm_template_deployment.function_keys.outputs["systemKeys"]}"
}
Error: on outputs.tf line 69, in output "syst_key":
69: value = "${azurerm_template_deployment.function_keys.outputs["systemKeys"]}"
|----------------
| azurerm_template_deployment.function_keys.outputs is empty map of string
output "syst_keys" {
value = "${lookup(azurerm_template_deployment.function_keys.outputs, "systemKeys")}"
}
Error: on outputs.tf line 77, in output "syst_key":
77: value = "${lookup(azurerm_template_deployment.function_keys.outputs, "systemKeys")}"
|----------------
| azurerm_template_deployment.function_keys.outputs is empty map of string
Call to function "lookup" failed: lookup failed to find 'systemKeys'.
为了在此函数上触发事件网格,我必须从我的 ARM 部署模板中恢复 systemKeys 的 terraform 输出中的值。我知道部署运行良好,我只是不知道如何使用 terraform 恢复这些值。
对于您的问题,您需要注意只有类型 String、Int 和 Bool 在 Terraform 中受支持。所以你需要在模板中更改输出类型,然后你可以在 Terraform 中输出它们。有关详细信息,请参阅 outputs。 Terraform 中的正确输出如下:
output "syst_key" {
value = "${azurerm_template_deployment.function_keys.outputs["systemKeys"]}"
}