【发布时间】:2020-05-09 13:43:54
【问题描述】:
使用: Terraform v0.12.6 + provider.azurerm v1.37.0
我正在通过 Terraform 创建多个 Azure 应用服务,并添加了标识块以使该应用成为 AD 应用。
resource "azurerm_app_service" "apiApp" {
count = "${length(var.apiName)}"
name = "${var.apiName[count.index]}-${var.environment}"
.
.
.
identity {
type = "SystemAssigned"
}
}
根据 Terraform 文档,https://www.terraform.io/docs/providers/azurerm/r/app_service.html#principal_id 我们可以通过以下方式将 App 的 Principal ID 导出到 output.tf 文件中:
${azurerm_app_service.apiApp.identity.0.principal_id}
由于在这种情况下我们有多个应用服务,所以我在 output.tf 文件中写了这个:
output "ApiAppPrincipalId" {
value = "${azurerm_app_service.apiApp.*.identity.0.principal_id}"
}
当我执行 terraform plan 时,我收到此错误:
Error: Invalid index
on modules\app-service\output.tf line 10, in output "ApiAppPrincipalId":
10: value = "${azurerm_app_service.apiApp.*.identity.0.principal_id}"
The given key does not identify an element in this collection value.
我也不确定 0 指的是什么。请帮忙。
【问题讨论】:
-
您的错误信息暗示
var.apiName是一个空字符串。 -
您需要提供更多您使用的 Terraform 代码。比如变量
apiName的定义。 -
焦点不在var.apiName上,你可以在里面放随机值。我需要有关错误消息的帮助。
-
经测试,问题不在输出设置或应用服务设置。
标签: azure azure-web-app-service terraform terraform-provider-azure