https://pulumi.com logo
Title
r

rapid-oil-61997

09/18/2020, 11:12 AM
Hi Guys. Its good to be here. I am trying out pulumi on Azure now. But i have a question ( I am a newbie to pulumi as well as kind of newbie to c# too ) . I have created a virtual network as below.
var virtualNetwork = new VirtualNetwork("vNet", new VirtualNetworkArgs
{
    Location = resourceGroup.Location,
    ResourceGroupName = resourceGroup.Name,
    Tags = tag,
    AddressSpaces = vnetAddressSpace,
    Name = "midhun-poc-pulumi-vnet",
    Subnets =
    {
        new VirtualNetworkSubnetArgs
        {
            Name = "subnet1",
            AddressPrefix = "10.198.10.0/29",
            SecurityGroup = nsg.Id
        },
        new VirtualNetworkSubnetArgs
        {
            Name = "subnet2",
            AddressPrefix = "10.198.10.8/29",
            SecurityGroup = nsg.Id
        }
    }
});
when creating network interface as below, how can i refer to the subnet that i created above in this section ?
var networkInterface = new NetworkInterface("nic", new NetworkInterfaceArgs
{
    Name = "midhun-poc-pulumi-vm-nic",
    Tags = tag,
    Location = resourceGroup.Location,
    ResourceGroupName = resourceGroup.Name,
    IpConfigurations = new NetworkInterfaceIpConfigurationArgs
    {
        Name = "midhun-poc-pulumi-nic-ip",
        SubnetId = 
    }
});
Any help is appreciated. Thanks in advance.
e

enough-oil-63049

09/20/2020, 6:13 AM
Hi Midhun, there are two ways to specify subnets - inline (as you have above) and the recommended way, as standalone resources that reference the virtual network: https://www.pulumi.com/docs/reference/pkg/azure/network/subnet/ As standalone resources, you can refer to them from other code.
c

colossal-room-15708

09/21/2020, 12:04 AM
don't forget that if you're using the subnet resource standalone, then you must run
pulumi up -r
(refresh) every time from then on, otherwise Azure ARM will try to delete your subnets.