title: Geting identity from an Azure function app in Terrraform
body: <p>I am trying to retrieve the Managed identity from an Azure funtion app and set an access policy in Azure Keyvault for the identity. The script looks like this (part of a larger script).</p>
  <pre><code>data &quot;azurerm_function_app&quot; &quot;funcidmngmtapp&quot; {
    name = &quot;func-adpidentitymngmt-${var.location}-${local.env}&quot;
    resource_group_name = azurerm_resource_group.azurefunctions.name
  }
  resource &quot;azurerm_key_vault_access_policy&quot; &quot;funcidmngmt&quot; {
      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 = [
        &quot;Get&quot;,
        &quot;List&quot;
      ]
  }
  </code></pre>
  <p>When doing a <code>terraform plan</code> it returns with the following error</p>
  <pre><code>Error: Unsupported attribute
  
    on resources.tf line 283, in resource &quot;azurerm_key_vault_access_policy&quot; &quot;funcidmngmt&quot;:
   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 &quot;azurerm_key_vault_access_policy&quot; &quot;funcidmngmt&quot;:
   284:     object_id = data.azurerm_function_app.funcidmngmtapp.identity.principal_id
  
  This value does not have any attributes.
  </code></pre>
  <p>As far as I understand the syntax is correct <a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/function_app" rel="nofollow noreferrer">https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/function_app</a>, but have problem understanding the error message.</p>
  <p>Thanks for any feedback</p>