https://pulumi.com logo
Title
p

proud-appointment-22284

10/27/2021, 6:56 PM
Hello everyone, It is possible to exclude the subnet resource from imported virtualnetwork in pulumi? (I cannot afford just re-create vnet resource through the pulumi) When I ran pulumi import "azure-native:network:VirtualNetwork name id", I got all resources associated with the vnet resource such as subnets.
I want to take the subnets part outside of the virtualnetwork resource but the pulumi is not able to handle such extractions, so I end up with this configuration.                                                                   const VirtualNetwork = new network.VirtualNetwork("VirtualNetwork-test", {
    addressSpace: {
        addressPrefixes: ["10.49.184.0/23"],
    },
    enableDdosProtection: false,
    location: "westeurope",
    resourceGroupName: "rsg-network",
    subnets: [{
        addressPrefix: "10.49.185.0/27",
        name: "subnet-test",
        privateEndpointNetworkPolicies: "Enabled",
        privateLinkServiceNetworkPolicies: "Enabled",
        type: "Microsoft.Network/virtualNetworks/subnets",
    }],
    virtualNetworkName: "VirtualNetwork-test",
},);    

const subnet = new network.Subnet("subnet-test", {
    addressPrefix: "10.49.185.0/27",
    name: "subnet-test",
    privateEndpointNetworkPolicies: "Enabled",
    privateLinkServiceNetworkPolicies: "Enabled",
    resourceGroupName: "rsg-network",
    subnetName: "subnet-test",
    type: "Microsoft.Network/virtualNetworks/subnets",
    virtualNetworkName: "VirtualNetwork-test",
}, {
    parent: VirtualNetwork,
});
My goal is to achieve that the subnets part information would be just removed from the virtaulnetwork resource and I will have only standalone subnet resource, so the code should look like:                                           const VirtualNetwork = new network.VirtualNetwork("VirtualNetwork-test", {
    addressSpace: {
        addressPrefixes: ["10.49.184.0/23"],
    },
    enableDdosProtection: false,
    location: "westeurope",
    resourceGroupName: "rsg-network",
    virtualNetworkName: "VirtualNetwork-test",
},);    

const subnet = new network.Subnet("subnet-test", {
    addressPrefix: "10.49.185.0/27",
    name: "subnet-test",
    privateEndpointNetworkPolicies: "Enabled",
    privateLinkServiceNetworkPolicies: "Enabled",
    resourceGroupName: "rsg-network",
    subnetName: "subnet-test",
    type: "Microsoft.Network/virtualNetworks/subnets",
    virtualNetworkName: "VirtualNetwork-test",
}, {
    parent: VirtualNetwork,
});