如何在 Pulumi C# 中为 Azure SQL 托管实例委派子网#

How to delegate a subnet for Azure SQL Managed Instance in Pulumi C#

Pulumi文档Create subnet with a delegation错误(没有设置SubnetArgs.Delegations属性)。

我尝试使用以下代码委托子网:

//
// Managed Insatnce subnet must be delegated
//
var spokeManagedInstanceSubnet = new Subnet($"{SpokeVirtualNetwork}.{ManagedInstanceSubnet}", new AzureNative.Network.SubnetArgs {
    SubnetName = ManagedInstanceSubnet,
    AddressPrefix = spokeSubnetCidrs[ManagedInstanceSubnet],
    VirtualNetworkName = spokeVnet.Name,
    ResourceGroupName = mainResourceGroup.Name,
    Delegations = new InputList<DelegationArgs> { new DelegationArgs {
            ServiceName = "Microsoft.Sql/managedInstances",
            Type = "Microsoft.Network/virtualNetworks/subnets/delegations"
        }
    }
}, new CustomResourceOptions { DependsOn = { spokeVnet } });

但出现以下错误:

error: Code="InvalidRequestFormat" Message="Cannot parse the request." Details=[]

如何为托管实例委托子网?

我认为您缺少的是 DelegationArgs 中的 Name 输入。所以它应该看起来像

var spokeManagedInstanceSubnet = new Subnet($"{SpokeVirtualNetwork}.{ManagedInstanceSubnet}", new AzureNative.Network.SubnetArgs {
    SubnetName = ManagedInstanceSubnet,
    AddressPrefix = spokeSubnetCidrs[ManagedInstanceSubnet],
    VirtualNetworkName = spokeVnet.Name,
    ResourceGroupName = mainResourceGroup.Name,
    Delegations = new InputList<DelegationArgs> { new DelegationArgs {
            ServiceName = "Microsoft.Sql/managedInstances",
            Type = "Microsoft.Network/virtualNetworks/subnets/delegations",
            Name = "" // name of delegation. Doesn't have to be the name of the managed instance
        }
    }
}, new CustomResourceOptions { DependsOn = { spokeVnet } });

我也认为你也不需要 Type

当我说“思考”时,我应该说我没有用 C# 和托管实例做过这件事,但我用 Typescript 和容器组做过类似的事情。

看起来像这样:

const subnet = new network.Subnet(`subnet`, {
      resourceGroupName: resourceGroup.name,
      virtualNetworkName: vnet.name,
      addressPrefix: "10.0.0.0/24",
      serviceEndpoints: [{
        service: "Microsoft.Sql"
      }],
      delegations: [{
        serviceName: "Microsoft.Containerinstance/containerGroups",
        name: `snet-delegation-containergroups`
      }]
    }, { parent: vnet });