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

问题描述 投票:1回答:1

使用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做同样的事情,但我没有办法做到这一点。

谢谢!

azure azure-sdk-.net azure-container-instances azure-fluent-api
1个回答
1
投票

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

与虚拟机一样,支持类似的功能。 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

© www.soinside.com 2019 - 2024. All rights reserved.