Sachin
Sachin

Reputation: 2148

Set-AzApiManagement with -UserAssignedIdentity is giving Bad Request

I am trying to assign a User Assigned Identity to a API Management instance on Azure from Powershell. I have taken reference from below link -

https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-use-managed-service-identity#code-try-7

I am trying the same code -

# Get an API Management instance
$apimService = Get-AzApiManagement -ResourceGroupName $resourceGroupName -Name $apiManagementName

# Create a user-assigned identity. This requires installation of the "Az.ManagedServiceIdentity" module.
$userAssignedIdentity = New-AzUserAssignedIdentity -Name $userAssignedIdentityName -ResourceGroupName $resourceGroupName

# Update an API Management instance
$userIdentities = @($userAssignedIdentity.Id)
Set-AzApiManagement -InputObject $apimService -UserAssignedIdentity $userIdentities

but it is always giving me below error message -

Set-AzApiManagement: Operation returned an invalid status code 'BadRequest'

What am I missing? What's wrong with the code? Any immediate help is appreciated!! Thanks in advance.. Am using Powershell..

Edit

The API Management instance is already having one User Assigned Identity, I am trying to add another..

Upvotes: 0

Views: 567

Answers (1)

Jim Xu
Jim Xu

Reputation: 23141

Regarding the issue, please refer to the following code

Connect-AzAccount

$userAssignedIdentity = New-AzUserAssignedIdentity -Name "myapi" -ResourceGroupName ""
$userIdentities = @($userAssignedIdentity.Id)

$apimService = Get-AzApiManagement -ResourceGroupName "" -Name "huryApim"

[string[]]$test= $apimService.Identity.UserAssignedIdentity.Keys
[string[]]$test += $userAssignedIdentity.Id

Set-AzApiManagement -InputObject $apimService -UserAssignedIdentity $test

enter image description here

Upvotes: 1

Related Questions