Azure Network Site

This page shows how to write Terraform and Azure Resource Manager for Network Site and write them securely.

azurerm_vpn_site (Terraform)

The Site in Network can be configured in Terraform with the resource name azurerm_vpn_site. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

main.tf#L43
resource "azurerm_vpn_site" "az_vpnsite_1" {
    location            = azurerm_resource_group.vWAN_RG.location
    resource_group_name = azurerm_resource_group.vWAN_RG.name
    virtual_wan_id      = azurerm_virtual_wan.default.id
    name                = "vpn_session1"
    link {
azurerm-vpn-gateway.tf#L16
resource "azurerm_vpn_site" "homelab1" {
  name                = "homelab1"
  resource_group_name = azurerm_resource_group.global.name
  location            = azurerm_vpn_gateway.canadacentral.location
  virtual_wan_id      = azurerm_virtual_wan.global.id

module.tf#L11
resource "azurerm_vpn_site" "vpn_site" {
  name                = azurecaf_name.vpn_site.result
  location            = var.location
  resource_group_name = var.resource_group_name
  virtual_wan_id      = var.virtual_wan_id
  address_cidrs       = try(var.settings.address_cidrs, null)
module.tf#L11
resource "azurerm_vpn_site" "vpn_site" {
  name                = azurecaf_name.vpn_site.result
  location            = var.location
  resource_group_name = var.resource_group_name
  virtual_wan_id      = var.virtual_wan_id
  address_cidrs       = try(var.settings.address_cidrs, null)
60-vpn-sites.tf#L1
resource "azurerm_vpn_site" "vpn_site" {
  for_each = var.vpn_sites

  address_cidrs = lookup(each.value, "address_cidrs", null) != null ? split(",", replace(lookup(each.value, "address_cidrs", null), " ", "")) : []
  device_model  = lookup(each.value, "device_model", null)
  device_vendor = lookup(each.value, "device_vendor", null)
module.tf#L11
resource "azurerm_vpn_site" "vpn_site" {
  name                = azurecaf_name.vpn_site.result
  location            = var.location
  resource_group_name = var.resource_group_name
  virtual_wan_id      = var.virtual_wan_id
  address_cidrs       = try(var.settings.address_cidrs, null)
vnet-gw.tf#L30
resource "azurerm_vpn_site" "microhack-eus2-onprem-site" {
  name                = "eus2-onprem-site"
  location            = azurerm_resource_group.vwan-microhack-hub-rg.location
  resource_group_name = azurerm_resource_group.vwan-microhack-hub-rg.name
  virtual_wan_id      = azurerm_virtual_wan.microhack-vwan.id

alpha.tf#L3
resource "azurerm_vpn_site" "alpha" {
  name                = "alpha-site"
  resource_group_name = data.terraform_remote_state.vwan.outputs.resource_group.name
  location            = data.terraform_remote_state.vwan.outputs.resource_group.location
  virtual_wan_id      = data.terraform_remote_state.vwan.outputs.virtual_wan.id

beta.tf#L3
resource "azurerm_vpn_site" "beta" {
  name                = "beta-site"
  resource_group_name = data.terraform_remote_state.vwan.outputs.resource_group.name
  location            = data.terraform_remote_state.vwan.outputs.resource_group.location
  virtual_wan_id      = data.terraform_remote_state.vwan.outputs.virtual_wan.id

main.tf#L70
resource "azurerm_vpn_site" "sites" {
  // This should be a map of objects
  provider            = azurerm.vwantarget
  for_each            = var.vwanVpnSiteConfigs
  name                = each.value["vpnSiteName"]
  resource_group_name = each.value["vpnSiteRgName"]

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Manages a VPN Site.

Tips: Best Practices for The Other Azure Network Resources

In addition to the azurerm_network_security_group, Azure Network has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

azurerm_network_security_group

Ensure to disable RDP port from the Internet

It is better to disable the RDP port from the Internet. RDP access should not be accepted from the Internet (*, 0.0.0.0, /0, internet, any), and consider using the Azure Bastion Service.

risk-label

azurerm_network_security_rule

Ensure to set a more restrictive CIDR range for ingress from the internet

It is better to set a more restrictive CIDR range not to use very broad subnets. If possible, segments should be divided into smaller subnets.

risk-label

azurerm_network_watcher_flow_log

Ensure to enable Retention policy for flow logs and set it to enough duration

It is better to enable a retention policy for flow logs. Flow logs show us all network activity in the cloud environment and support us when we face critical incidents.

Review your Azure Network settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

Microsoft.Network/vpnSites (Azure Resource Manager)

The vpnSites in Microsoft.Network can be configured in Azure Resource Manager with the resource name Microsoft.Network/vpnSites. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

wanFirstTime.json#L22
            "type": "Microsoft.Network/vpnSites",
            "apiVersion": "2018-11-01",
            "name": "branch-ne",
            "location": "westeurope",
            "dependsOn": [
                "[variables('virtualWanName')]"
vpnsites.json#L3
  "type": "Microsoft.Network/vpnSites",
  "apiVersion": "2019-04-01",
  "location": "string",
  "tags": {},
  "properties": {
    "virtualWan": {
wan.json#L22
            "type": "Microsoft.Network/vpnSites",
            "apiVersion": "2018-11-01",
            "name": "branch-ne",
            "location": "westeurope",
            "dependsOn": [
                "[variables('virtualWanName')]"
VpnSiteList.json#L15
                        "type": "Microsoft.Network/vpnSites",
                        "tags": {
                            "key1": "value1"
                        },
                        "properties": {
                            "provisioningState": "Succeeded",
VpnSiteList.json#L15
                        "type": "Microsoft.Network/vpnSites",
                        "tags": {
                            "key1": "value1"
                        },
                        "properties": {
                            "provisioningState": "Succeeded",
VpnSiteListByResourceGroup.json#L16
                        "type": "Microsoft.Network/vpnSites",
                        "tags": {
                            "key1": "value1"
                        },
                        "properties": {
                            "provisioningState": "Succeeded",
VpnSiteListByResourceGroup.json#L16
                        "type": "Microsoft.Network/vpnSites",
                        "tags": {
                            "key1": "value1"
                        },
                        "properties": {
                            "provisioningState": "Succeeded",
VpnSiteUpdateTags.json#L21
        "type": "Microsoft.Network/vpnSites",
        "tags": {
          "key1": "value1",
          "key2": "value2"
        },
        "properties": {
VpnSiteUpdateTags.json#L21
        "type": "Microsoft.Network/vpnSites",
        "tags": {
          "key1": "value1",
          "key2": "value2"
        },
        "properties": {
VpnSitePut.json#L39
                "type": "Microsoft.Network/vpnSites",
                "tags": {
                    "key1": "value1"
                },
                "properties": {
                    "provisioningState": "Succeeded",

Parameters

  • name required - string
  • type required - string
  • apiVersion required - string
  • location required - string

    Resource location.

  • tags optional - string

    Resource tags.

  • properties required
      • virtualWan optional
          • id required - string

            Resource ID.

      • deviceProperties optional
          • deviceVendor optional - string

            Name of the device Vendor.

          • deviceModel optional - string

            Model of the device.

          • linkSpeedInMbps optional - integer

            Link speed.

      • ipAddress optional - string

        The ip-address for the vpn-site.

      • siteKey optional - string

        The key for vpn-site that can be used for connections.

      • addressSpace optional
          • addressPrefixes required - array

            A list of address blocks reserved for this virtual network in CIDR notation.

      • bgpProperties optional
          • asn optional - integer

            The BGP speaker's ASN.

          • bgpPeeringAddress optional - string

            The BGP peering address and BGP identifier of this BGP speaker.

          • peerWeight optional - integer

            The weight added to routes learned from this BGP speaker.

          • bgpPeeringAddresses optional array
              • ipconfigurationId optional - string

                The ID of IP configuration which belongs to gateway.

              • customBgpIpAddresses optional - array

                The list of custom BGP peering addresses which belong to IP configuration.

      • isSecuritySite optional - boolean

        IsSecuritySite flag.

      • vpnSiteLinks optional array
          • properties optional
              • linkProperties optional
                  • linkProviderName optional - string

                    Name of the link provider.

                  • linkSpeedInMbps optional - integer

                    Link speed.

              • ipAddress optional - string

                The ip-address for the vpn-site-link.

              • fqdn optional - string

                FQDN of vpn-site-link.

              • bgpProperties optional
                  • asn optional - integer

                    The BGP speaker's ASN.

                  • bgpPeeringAddress optional - string

                    The BGP peering address and BGP identifier of this BGP speaker.

          • name optional - string

            The name of the resource that is unique within a resource group. This name can be used to access the resource.

      • o365Policy optional
          • breakOutCategories optional
              • allow optional - boolean

                Flag to control allow category.

              • optimize optional - boolean

                Flag to control optimize category.

              • default optional - boolean

                Flag to control default category.

Frequently asked questions

What is Azure Network Site?

Azure Network Site is a resource for Network of Microsoft Azure. Settings can be wrote in Terraform.

Where can I find the example code for the Azure Network Site?

For Terraform, the rickchen918/vwan, raykao/hub-spoke-environment and aztfmod/terraform-azurerm-caf source code examples are useful. See the Terraform Example section for further details.

For Azure Resource Manager, the tkubica12/azure-virtual-wan, da-edra/scraping-azure and tkubica12/azure-virtual-wan source code examples are useful. See the Azure Resource Manager Example section for further details.