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

时间:2019-04-23 03:17:39

标签: azure azure-sdk-.net azure-container-instances azure-fluent-api

使用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做同样的事情,但是我看不到这样做的方法。

谢谢!

1 个答案:

答案 0 :(得分:1)

我认为您可能对此是正确的。我也尝试浏览用于.NET的Azure管理库的源代码,但找不到任何有助于使用系统分配的或用户分配的身份进行创建的方法或帮助程序。

对于虚拟机,也支持类似的功能。 Source code

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

我本来希望在属于ContainerInstance的类中看到类似的方法,例如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

相关问题