如何使用 .Net Fluent SDK 设置 Azure 容器实例托管服务标识参数

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

使用 azure-cli 创建 Azure 容器实例,我可以将托管标识的资源 ID 指定为 --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.

我尝试用 .Net Fluent Management SDK 做同样的事情,但我没有找到这样做的方法。

谢谢!

我想你可能是对的。我也尝试查看 .NET 的 Azure 管理库的源代码,但找不到任何有助于使用系统分配或用户分配的标识进行创建的方法或助手。

虚拟机支持类似的功能。 Source code

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

我希望在属于 ContainerInstance like ContainerGroupImpl 的 类 中看到类似的方法,但我没有。

免责声明:如您所见,我说的是基于手动搜索而非基于官方文档,因此我可能会遗漏某些内容。

可能的选择

如果您有兴趣从基于 .NET/C# 的代码执行此操作(因为您正在寻找 .NET SDK),一种替代方法是使用直接 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

您可以在正文中指定要使用的身份

"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