0

The Pulumi doc Create subnet with a delegation is wrong (it did not set SubnetArgs.Delegations property).

I tried to delegate subnet with following code:

//
// 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 } });

But getting the following error:

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

How to delegate subnet for managed Instance ?

MD TAREQ HASSAN
  • 1,188
  • 20
  • 46

1 Answers1

0

I think what you're missing is the Name input in the DelegationArgs. So it should look something like

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 } });

I also think you don't need Type in there either.

When I say "think", I should say that I've not done this with C# and managed instances, but I've done similar with Typescript and container groups.

That looked something like this:

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 });
Piers Karsenbarg
  • 3,105
  • 5
  • 31
  • 67