title: How to add Azure User Assigned Managed Identity to Azure AD group in Terraform?
body: <p>I am trying to assign User Assigned Managed identity to AAD group. I have following Terraform code:</p>
  <pre><code>resource &quot;azurerm_user_assigned_identity&quot; &quot;myid&quot; {
    name                = &quot;my_identity&quot;
    resource_group_name = azurerm_resource_group.somerg.name
    location            = azurerm_resource_group.somerg.location
  }
  
  data &quot;azuread_group&quot; &quot;existinggroup&quot; {
    display_name     = &quot;existing_group&quot;
    security_enabled = true
  }
  
  resource &quot;azuread_group_member&quot; &quot;mygrpmember&quot; {
    group_object_id  = data.azuread_group.existinggroup.id
    member_object_id = azurerm_user_assigned_identity.myid.id
  }
  </code></pre>
  <p>During <code>plan</code> operation, I get following error:</p>
  <pre><code>Error: Value must be a valid UUID
  </code></pre>
  <p>When I change <code>myid.id</code> to <code>myid.principal_id</code> in last line of above code, I get an error during <code>apply</code> operation:</p>
  <pre><code>Error: Could not retrieve member principal object &quot;4e83cd6b-d984-4484-8fb2-3ae6e1667ef9&quot;
  ODataId was nil
  </code></pre>
  <p>When I try with <code>myid.client_id</code> I get this during <code>apply</code>:</p>
  <pre><code>Error: Could not retrieve principal object &quot;838c2662-5fe2-484c-bb52-f70994fa1d8b&quot;
  DirectoryObjects.BaseClient.Get(): Get &quot;https://graph.microsoft.com/v1.0/5989ece0-f90e-40bf-9c79-1a7beccdb861/directoryObjects/838c2662-5fe2-484c-bb52-f70994fa1d8b&quot;: GET https://graph.microsoft.com/v1.0/5989ece0-f90e-40bf-9c79-1a7beccdb861/directoryObjects/838c2662-5fe2-484c-bb52-f70994fa1d8b giving up after 9 attempt(s)
  </code></pre>
  <p>What am I doing wrong?</p>