从 Terraform 中的 Azure 函数应用获取标识

Geting identity from an Azure function app in Terrraform

我正在尝试从 Azure 函数应用程序检索托管身份,并在 Azure Keyvault 中为该身份设置访问策略。该脚本如下所示(较大脚本的一部分)。

data "azurerm_function_app" "funcidmngmtapp" {
  name = "func-adpidentitymngmt-${var.location}-${local.env}"
  resource_group_name = azurerm_resource_group.azurefunctions.name
}
resource "azurerm_key_vault_access_policy" "funcidmngmt" {
    key_vault_id = azurerm_key_vault.general.id 
    tenant_id = data.azurerm_function_app.funcidmngmtapp.identity.tenant_id
    object_id = data.azurerm_function_app.funcidmngmtapp.identity.principal_id

    secret_permissions = [
      "Get",
      "List"
    ]
}

在执行 terraform plan 时 returns 出现以下错误

Error: Unsupported attribute

  on resources.tf line 283, in resource "azurerm_key_vault_access_policy" "funcidmngmt":
 283:     tenant_id = data.azurerm_function_app.funcidmngmtapp.identity.tenant_id

This value does not have any attributes.


Error: Unsupported attribute

  on resources.tf line 284, in resource "azurerm_key_vault_access_policy" "funcidmngmt":
 284:     object_id = data.azurerm_function_app.funcidmngmtapp.identity.principal_id

This value does not have any attributes.

据我了解,语法是正确的 https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/function_app,但无法理解错误消息。

感谢任何反馈

identity 属性是一个列表,所以使用这个(重要的部分是 .0.):

data.azurerm_function_app.funcidmngmtapp.identity.0.principal_id