Azure / Azure/azure-cli

Resource not found after assigning identity to web app #79294

Open
#19,164 2 comments 0 reactions 0 assignees View on GitHub
AAD act-identity-squad Service Attention
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

_Originally posted by @HannesWurm in https://github.com/MicrosoftDocs/azure-docs/issues/79294#issue-960818214_

**Describe the bug**

In this [tutorial](https://docs.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-connect-msi) you have those steps to create a managed identity and then assign the created service principal to an ad group:

```
az webapp identity assign --resource-group myResourceGroup --name
groupid=$(az ad group create --display-name myAzureSQLDBAccessGroup --mail-nickname myAzureSQLDBAccessGroup --query objectId --output tsv)
msiobjectid=$(az webapp identity show --resource-group myResourceGroup --name --query principalId --output tsv)
az ad group member add --group $groupid --member-id $msiobjectid
az ad group member list -g $groupid
```

If I use an existing group instead of creating a new group like that and:

` az ad group member add --group $groupid --member-id $msiobjectid-`

or try to get the principal from ad like that:

` $servicePrincipal = az ad sp show --id $msiobjectid`

Where `$adGroupName` is an existing group. And then try to assign the created principal, I often get the error:

`az : ERROR: Resource 'msiobjectid' does not exist or one of its queried reference-property objects are not present.`

Where 'msiobjectid' is the acutal GUID of the service principal.

If I put a sleep between the identity assign call and the assignment of the service principal to the group like that:

`Start-Sleep -s 15`

It always works.

Is this your recommendation or can I somehow make sure that the service principal exists after assigning the identity to a web app (except for polling in a loop until the az ad show command returns no error)

Thanks in advance

best regards
Hannes

**To Reproduce**
Mentioned above.

**Expected behavior**
Should be able to grant permissions to managed identity without errors or delay

**Environment summary**

**Additional context**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.