Search code examples
azureazure-sql-databaseidentity-management

How to add user assigned identity in azure sql using azure cli?


I want to do the following function using Azure CLI. turn the system assigned service principal off, Add a user managed identity and make it the primary identity using Azure CLI. Would much appreciate the help.

Reference: https://learn.microsoft.com/en-us/azure/azure-sql/database/authentication-azure-ad-user-assigned-managed-identity?view=azuresql#set-a-managed-identity-in-the-azure-portal


Solution

  • I tried to replicate the issue in my environment with below code:

     az sql mi update -g Analytics-Resources -n sqlmanagedinstanceshared -i \ --user-assigned-identity-id /subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/Analytics-Resources/providers/Microsoft.ManagedIdentity/userAssignedIdentities/dbm \ --identity-type UserAssigned --pid /subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/Analytics-Resources/providers/Microsoft.ManagedIdentity/userAssignedIdentities/dbm
    

    I got the same error:

    enter image description here

    This error I got because of extra back slash at -i I removed that tried to exucute the code:

    az sql mi update -g Analytics-Resources -n sqlmanagedinstanceshared -i  --user-assigned-identity-id /subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/Analytics-Resources/providers/Microsoft.ManagedIdentity/userAssignedIdentities/dbm \ --identity-type UserAssigned --pid /subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/Analytics-Resources/providers/Microsoft.ManagedIdentity/userAssignedIdentities/dbm
    

    The error was resolved, and it executed successfully.

    enter image description here