Hi Guys, I’m quiet new to `pulumi` and `typescript...
# azure
w
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
subnets themselves don't have an ID in ARM, you need to get the vnet ID and append
Copy code
/subnets/<subnetName>
w
@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
Ignore me, you are correct that it does have an ID object. What yo've written should work
w
@miniature-leather-70472 is it possible to get subnet id in case I created them inside
network.VirtualNetwork
?
a
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