Virtual Network

Overview

The Virtual Network builder (vnet) is used to create Azure Virtual Network instances.

  • Virtual Network (Microsoft.Network/virtualNetworks)
  • Subnets (Microsoft.Network/virtualNetworks/subnets)

Builder Keywords

ResourceKeywordPurpose
vnetnameSets the name of the virtual network.
vnetadd_address_spacesAdds address spaces to the virtual network.
vnetadd_subnetsAdds subnets to the virtual network.
vnetbuild_address_spacesAutomatically builds address spaces for subnet names and sizes.
vnetadd_tagsAdds a set of tags to the resource
vnetadd_tagAdds a tag to the resource
subnetnameName of the subnet resource
subnetprefixSubnet prefix in CIDR notation (e.g. 192.168.100.0/24)
subnetadd_delegationsAdds one or more delegations to this subnet.
addressSpacespaceWhen using build_address_space this specifies the address space.
addressSpacesubnetsSpecifies the subnets to build automatically.
addressSpacebuild_subnetSpecifies the name, size, and service delegations for the subnet.

Example - Manual Subnets

A virtual network is defined with the vnet builder. Address spaces and subnets should be added, taking care to ensure the subnets are contained within an address space on the virtual network.

open Farmer
open Farmer.Builders

let myVnet = vnet {
    name "my-vnet"
    add_address_spaces [ "192.168.200.0/22" ]
    add_subnets [
        subnet {
            name "vms"
            prefix "192.168.200.0/24"
        }
        subnet {
            name "containers"
            prefix "192.168.201.0/24"
            add_delegations [
                SubnetDelegationService.ContainerGroups
            ]
        }
        subnet {
            name "databases"
            prefix "192.168.202.0/24"
            add_delegations [
                SubnetDelegationService.SqlManagedInstances
            ]
        }
    ]
}

let deployment = arm {
    location Location.NorthEurope
    add_resource myVnet
}

Example - Automatically Build Subnets

Address spaces and subnets can be built out automatically to ensure the subnets are contained within the address spaces. This reduces the need for “IP math” to determine the start addresses for contiguous networks of different sizes.

open Farmer
open Farmer.Builders

let myVnet = vnet {
    name "my-vnet"
    build_address_spaces [
        addressSpace {
            space "10.28.0.0/16"
            subnets [
                buildSubnet "vms" 26
                buildSubnet "services" 24
                buildSubnet "corporate-west" 18
                buildSubnet "corporate-east" 18
                buildSubnet "GatewaySubnet" 28
                buildSubnetDelegations "containers" 27 [ SubnetDelegationService.ContainerGroups ]
            ]
        }
        addressSpace {
            space "10.30.0.0/16"
            subnets [
                buildSubnet "remote-office" 23
                buildSubnet "reserved" 24
                buildSubnet "GatewaySubnet" 28
            ]
        }
    ]
}

let deployment = arm {
    location Location.NorthEurope
    add_resource myVnet
}