title: Terraform Azure Data Factory Identity
body: <p>I'm trying to grant access to a keyvault for the newly created data factory. To achieve this I had following code ...</p>
  <pre><code>    module &quot;subscription&quot; {
        source = &quot;../../general/subscription_getdetails&quot;
      }
      
      module &quot;df_resourcegroup&quot; {
        source = &quot;../../general/rg_getdetails&quot;
        rg_name_solution = var.df_rg_name_solution
        rg_name_seqnr    = var.df_rg_name_seqnr
      }
      
      module &quot;location&quot; {
        source = &quot;../../general/location/location_getdetails&quot;
        location_name = var.df_location_name
        location_tier = var.df_location_tier
      }
      
      module &quot;keyvault&quot; {
        source = &quot;../../security/kv_getdetails&quot;
        kv_name_solution    = var.kv_name_solution
        kv_name_seqnr       = var.kv_name_seqnr
        kv_name_purpose     = var.kv_name_purpose
        kv_location_name    = var.kv_location_name
        kv_location_tier    = var.kv_location_tier
        kv_rg_name_solution = var.kv_rg_name_solution
        kv_rg_name_seqnr    = var.kv_rg_name_seqnr
      }
      
      resource &quot;azurerm_data_factory&quot; &quot;df&quot; {
        name                     = &quot;adf-${module.df_resourcegroup.sitecode}-${module.subscription.environment}-${var.df_name_dataset}-${var.df_name_seqnr}&quot;
        location                 = module.location.azure
        resource_group_name      = module.df_resourcegroup.rg.name
        public_network_enabled   = var.df_allow_public_access
    identity {
        type = &quot;SystemAssigned&quot;
    }    }
      
      
      resource &quot;azurerm_key_vault_access_policy&quot; &quot;df_grant_keyvault_read&quot; {
        key_vault_id = module.keyvault.kv.id
        tenant_id    = azurerm_data_factory.df.identity[0].tenant_id
        object_id    = azurerm_data_factory.df.identity[0].principal_id
      
        key_permissions = [
          &quot;Get&quot;,
        ]
      
        secret_permissions = [
          &quot;Get&quot;,
        ]
      }
  </code></pre>
  <p>But there must be something wrong with this as I'm getting this error... (I've tried not to address it as a list, doesn't work).</p>
  <pre><code>│ Error: Invalid index
  │ 
  │   on _modules/das/df_create/main.tf line 68, in resource &quot;azurerm_key_vault_access_policy&quot; &quot;df_grant_keyvault_read&quot;:
  │   68:   tenant_id    = azurerm_data_factory.df.identity[0].tenant_id
  │     ├────────────────
  │     │ azurerm_data_factory.df.identity is empty list of object
  │ 
  │ The given key does not identify an element in this collection value.
  </code></pre>