Virtual Network

Overview

The virtual network builder is used to deploy virtual networks and their subnets.

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

The Virtual Network module contains four builders

  • The vnet builder is used to create Azure Virtual Network instances.
  • The subnet builder is used within the vnet builder to define subnets.
  • The addressSpace builder can be used to automatically generate subnets based on the sizes of networks needed within the address space.
  • The subnetSpec builder is used to define the automatically generated subnets, with the primary different from the subnet builder being that you define the size for the prefix, and not the address.

Builder Keywords

Virtual Network: vnet
KeywordPurpose
nameSets the name of the virtual network.
add_address_spacesAdds address spaces to the virtual network.
add_subnetsAdds subnets to the virtual network.
build_address_spacesAutomatically builds address spaces for subnet names and sizes.
add_tagsAdds a set of tags to the resource
add_tagAdds a tag to the resource
add_peerAdds VNet peering between this and another VNet (one/two-way)
add_peersAdds VNet peering between this and other VNets (one/two-way)
Subnet: subnet
KeywordPurpose
nameName of the subnet resource
prefixSubnet prefix in CIDR notation (e.g. 192.168.100.0/24)
add_prefixesAdd one or more prefixes for this subnet. If using IPv6, an IPv4 prefix is also required.
nat_gatewaySpecify the NAT gateway for the subnet from the same deployment.
link_to_nat_gatewaySpecify an existing NAT gateway for the subnet.
network_security_groupSpecify the network security group from the same deployment.
link_to_network_security_groupSpecify an existing network security group for this subnet.
link_to_vnetLink a standalone subnet to a vnet in the same template.
link_to_unmanaged_vnetLink a standalone subnet to an existing vnet that is already deployed.
add_delegationsAdds one or more delegations to this subnet.
add_service_endpointsAdds one or more service endpoints to this subnet.
associate_service_endpoint_policiesAssociates a subnet with an existing service policy.
allow_private_endpointsEnable or disable support for private endpoints, default is Disabled
private_link_service_network_policiesEnable or disable support for private link service network polices, default is Disabled
depends_onAdd depdendencies on the deployment of another resource.
Automatically build out an address space: addressSpace
KeywordPurpose
spaceWhen using build_address_space this specifies the address space.
subnetsSpecifies the subnets to build automatically.
Specify subnets in automatic address space: subnetSpec
KeywordPurpose
nameSpecifies the name of the subnet to build.
sizeSpecifies the size of the subnet to build, default is /24.
nat_gatewaySpecify the NAT gateway for the subnet from the same deployment.
link_to_nat_gatewaySpecify an existing NAT gateway for the subnet.
network_security_groupSpecify the network security group from the same deployment.
link_to_network_security_groupSpecify an existing network security group for the subnet.
add_delegationsAdds service delegations for the subnet.
add_service_endpointsAdds service endpoints for the subnet.
add_service_endpoint_policiesAssociates the service endpoint policies with the subnet.
allow_private_endpointsEnable or disable support for private endpoints, default is Disabled
private_link_service_network_policiesEnable or disable support for private link service network polices, default is Disabled

Configuration Members

MemberPurpose
SubnetIdsGets a map of subnet ResourceIds by subnet name

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
            ]
            add_service_endpoints [
                EndpointServiceType.Storage, [Location.NorthEurope; Location.WestEurope]
            ]
        }
        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 [
                subnetSpec {
                    name "vms"
                    size 26
                }
                subnetSpec {
                    name "services"
                    size 24
                }
                subnetSpec {
                    name "corporate-west"
                    size 18
                }
                subnetSpec {
                    name "corporate-east"
                    size 18
                }
                subnetSpec {
                    name "corporate-east"
                    size 18
                }
                subnetSpec {
                    name "GatewaySubnet"
                    size 28
                }
                subnetSpec {
                    name "containers"
                    size 27
                    add_delegations [SubnetDelegationService.ContainerGroups]
                    add_service_endpoints [
                        EndpointServiceType.Storage, [
                            Location.NorthEurope
                            Location.WestEurope
                        ]
                    ]
                }
            ]
        }
        addressSpace {
            space "10.30.0.0/16"
            subnets [
                subnetSpec {
                    name "remote-office"
                    size 23
                }
                subnetSpec {
                    name "applications"
                    size 24
                    add_service_endpoints [
                        EndpointServiceType.Storage, [
                            Location.NorthEurope
                            Location.WestEurope
                        ]
                    ]
                }
                subnetSpec {
                    name "reserved"
                    size 24
                }
                subnetSpec {
                    name "GatewaySubnet"
                    size 28
                }
            ]
        }
    ]
}

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