azureazure-sdk-.netazure-container-instancesazure-fluent-api

How To Set Azure Container Instance Managed Service Identity Arguments With .Net Fluent SDK


Creating Azure Container Instance using azure-cli, I can specify a resource id of a managed identity as a parameter of --assigned-identity

Managed Service Identity Arguments
    --assign-identity                : Space-separated list of assigned identities. Assigned
                                       identities are either user assigned identities (resource IDs)
                                       and / or the system assigned identity ('[system]'). See
                                       examples for more info.

I try to do the same with .Net Fluent Management SDK, but I don't see a way to do that.

Thanks!


Solution

  • I think you may be right about this. I tried looking through the source code for Azure Management Libraries for .NET as well and couldn't find any methods or helpers that would help with creation using system assigned or user assigned identity.

    Like similar functionality is supported in case of Virtual Machines. Source code

    public VirtualMachineImpl WithExistingUserAssignedManagedServiceIdentity(IIdentity identity)
    {
        this.virtualMachineMsiHelper.WithExistingExternalManagedServiceIdentity(identity);
        return this;
    }
    

    I would have expected to see similar methods in classes belonging to ContainerInstance like ContainerGroupImpl, but I don't.

    Disclaimer: As you can see, I say this based on manual search and not based on official documentation so it's possible I could be missing something.

    Possible Alternative

    If you're interested in doing this from .NET/C# based code (since you're looking in .NET SDK), one alternative could be to use the direct REST API.

    Container Groups - Create or Update

    PUT https://management.azure.com/subscriptions/subid/resourceGroups/demo/providers/Microsoft.ContainerInstance/containerGroups/demo1?api-version=2018-10-01
    

    You can specify the identity to be used in body

    "identity": {
        "type": "SystemAssigned, UserAssigned",
        "userAssignedIdentities": {
          "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/identity-name": {}
        }
    

    Full for REST API call example here