https://pulumi.com logo
#azure
Title
# azure
w

wooden-receptionist-75654

09/10/2021, 12:28 PM
Hi Guys, I’m quiet new to
pulumi
and
typescript
and tryin’ to understand how can I get
subnet id
ouf of network.VirtualNetwork
Copy code
import * as network from "@pulumi/azure-native/network";

const virtualNetwork = new network.VirtualNetwork("virtualNetwork", {
  addressSpace: "10.0.0.0/23",
  location: "eastus",
  resourceGroupName: resourceGroup.name,
  virtualNetworkName: managedClusterName,
  subnets: [
    {
      addressPrefix: "10.0.0.0/24",
      name: "subnet-a",
    },
    {
      addressPrefix: "10.0.1.0/24",
      name: "subnet-b",
    },
  ]
});
I can see that virtualNetwork has a subnets list. Didn’t het how to fetch id. Thanks
m

miniature-leather-70472

09/10/2021, 1:16 PM
subnets themselves don't have an ID in ARM, you need to get the vnet ID and append
Copy code
/subnets/<subnetName>
w

wooden-receptionist-75654

09/10/2021, 2:29 PM
@miniature-leather-70472 sorry, but how can I do this? My idea is to to do similar to
Copy code
const subA = new network.Subnet("subnetA", {
  addressPrefix: "10.0.0.0/24",
  resourceGroupName: resourceGroup.name,
  subnetName: "subnet-a",
  virtualNetworkName: virtualNetwork.name,
}); 

subA.id
This objects has id method as I can see.
m

miniature-leather-70472

09/10/2021, 2:53 PM
Ignore me, you are correct that it does have an ID object. What yo've written should work
w

wooden-receptionist-75654

09/11/2021, 1:48 PM
@miniature-leather-70472 is it possible to get subnet id in case I created them inside
network.VirtualNetwork
?
a

adorable-soccer-30455

09/17/2021, 12:04 PM
You could create the subnet and use the ID later;
Copy code
const virtualNetwork = new network.VirtualNetwork("networkname", {
    resourceGroupName: resgrpName,
    addressSpace: {
        addressPrefixes: [testConfig.require("NetworkSegment")],
    },
});

const Subnet = new network.Subnet("subnetname", {
    resourceGroupName: resgrpName,
    virtualNetworkName: virtualNetwork.name,
    addressPrefix: testConfig.require("NetworkSegment"),
    networkSecurityGroup: {
        id: NSG.id
    },
});

const networkInterface1 = new network.NetworkInterface("test-nic", {
    resourceGroupName: resgrpName,
    ipConfigurations: [{
        name: "test1ipcfg",
        subnet: { id: Subnet.id },
        privateIPAllocationMethod: network.IPAllocationMethod.Dynamic,
        publicIPAddress: { id: publicIp1.id },
    }],
});
🙏 1
3 Views