Azure Network Virtual Hub

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

azurerm_virtual_hub (Terraform)

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

Example Usage from GitHub

vwan.tf#L11
resource "azurerm_virtual_hub" "HUB-WestEurope" {
  address_prefix      = "10.0.0.0/24"
  location            = "WestEurope"
  name                = "HUB-WestEurope"
  resource_group_name = var.lab-rg
  virtual_wan_id      = azurerm_virtual_wan.vwan-demo.id
vwan.tf#L6
   resource "azurerm_virtual_hub" "microhack-eus2-hub" {
    name                = "microhack-eus2-hub"
    resource_group_name = azurerm_resource_group.vwan-microhack-hub-rg.name
    location            = var.location-hub-1
    virtual_wan_id      = azurerm_virtual_wan.microhack-vwan.id
    address_prefix      = var.hub1-cidr
vwan.tf#L8
  resource "azurerm_virtual_hub" "microhack-we-hub" {
    name                = "microhack-we-hub"
    resource_group_name = azurerm_resource_group.vwan-microhack-hub-rg.name
    location            = var.location-vwan-we-hub
    virtual_wan_id      = azurerm_virtual_wan.microhack-vwan.id
    address_prefix      = "192.168.0.0/24"
main.tf#L32
resource "azurerm_virtual_hub" "vhub" {

  count                = length(var.hubnames)
  name                 = var.hubnames[count.index]
  resource_group_name  = var.rsg
  address_prefix       = var.adress_prefixes[count.index]
main.tf#L32
resource "azurerm_virtual_hub" "vhub" {

  count                = length(var.hubnames)
  name                 = var.hubnames[count.index]
  resource_group_name  = var.rsg
  address_prefix       = var.adress_prefixes[count.index]
VWAN-Multi-Hub.tf#L15
resource "azurerm_virtual_hub" "vwan-001-hub-neu" {
  name                = "neu-vwan-hub-001"
  resource_group_name = azurerm_resource_group.neu-rsg-vwan-001.name
  location            = azurerm_resource_group.neu-rsg-vwan-001.location

  virtual_wan_id = azurerm_virtual_wan.vwan-001.id
main.tf#L12
resource "azurerm_virtual_hub" "test" {
  name                = "cwan-vhub"
  resource_group_name = azurerm_resource_group.test.name
  location            = azurerm_resource_group.test.location
  virtual_wan_id      = azurerm_virtual_wan.test.id
  address_prefix      = "10.0.1.0/24"
vwan.tf#L30
resource "azurerm_virtual_hub" "westeu_vHub" {
  name                = "westeu_vHub"
  resource_group_name = azurerm_resource_group.cloudteam_mremini_vWAN.name
  location            = "westeurope"
  virtual_wan_id      = azurerm_virtual_wan.cloudteam_mremini_vWAN.id
  address_prefix      = "10.80.0.0/24"
main.tf#L9
resource "azurerm_virtual_hub" "main" {
  for_each            = { for hub in var.hubs : hub.region => hub }
  name                = each.key
  resource_group_name = var.resource_group_name
  location            = var.resource_group_location
  virtual_wan_id      = azurerm_virtual_wan.main.id
main.tf#L34
resource "azurerm_virtual_hub" "example" {
  count               = var.enabled ? 1 : 0
  name                = var.hub_names
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  virtual_wan_id      = azurerm_virtual_wan.example.id

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 Virtual Hub within a Virtual WAN.

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/virtualHubs (Azure Resource Manager)

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

Example Usage from GitHub

routeserver.json#L49
            "type": "Microsoft.Network/virtualHubs",
            "apiVersion": "2021-02-01",
            "name": "[parameters('routeserverName')]",
            "location": "[parameters('location')]",
            "properties": {
                "sku": "Standard",
azuredeploy.json#L130
      "type": "Microsoft.Network/virtualHubs",
      "apiVersion": "2020-05-01",
      "name": "[variables('virtual_hub1_cfg').name]",
      "location": "[parameters('hub1_location')]",
       "dependsOn": [
        "[resourceId('Microsoft.Network/virtualWans', parameters('vWANname'))]"
main.json#L52
      "type": "Microsoft.Network/virtualHubs",
      "apiVersion": "2020-05-01",
      "name": "[variables('virtual_hub_cfg').name]",
      "location": "[parameters('location')]",
      "properties": {
        "addressPrefix": "[variables('virtual_hub_cfg').addressSpacePrefix]",
azuredeploy.json#L130
      "type": "Microsoft.Network/virtualHubs",
      "apiVersion": "2020-05-01",
      "name": "[variables('virtual_hub1_cfg').name]",
      "location": "[parameters('hub1_location')]",
       "dependsOn": [
        "[resourceId('Microsoft.Network/virtualWans', parameters('vWANname'))]"
azuredeploy.json#L130
      "type": "Microsoft.Network/virtualHubs",
      "apiVersion": "2020-05-01",
      "name": "[variables('virtual_hub1_cfg').name]",
      "location": "[parameters('hub1_location')]",
       "dependsOn": [
        "[resourceId('Microsoft.Network/virtualWans', parameters('vWANname'))]"
azuredeploy.json#L130
      "type": "Microsoft.Network/virtualHubs",
      "apiVersion": "2020-05-01",
      "name": "[variables('virtual_hub1_cfg').name]",
      "location": "[parameters('hub1_location')]",
       "dependsOn": [
        "[resourceId('Microsoft.Network/virtualWans', parameters('vWANname'))]"
azuredeploy.json#L100
            "type": "Microsoft.Network/virtualHubs",
            "apiVersion": "2020-05-01",
            "name": "[variables('virtual_hub1_cfg').name]",
            "location": "[parameters('hub1_location')]",
            "dependsOn": [
                "[resourceId('Microsoft.Network/virtualWans', parameters('vWANname'))]"
azuredeploy.json#L130
      "type": "Microsoft.Network/virtualHubs",
      "apiVersion": "2020-05-01",
      "name": "[variables('virtual_hub1_cfg').name]",
      "location": "[parameters('hub1_location')]",
       "dependsOn": [
        "[resourceId('Microsoft.Network/virtualWans', parameters('vWANname'))]"
template.json#L106
      "type": "Microsoft.Network/virtualHubs",
      "apiVersion": "2020-06-01",
      "name": "[parameters('firstRouteServerName')]",
      "location": "[parameters('location')]",
      "dependsOn": [
          "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetName'))]",
azuredeploy.json#L130
      "type": "Microsoft.Network/virtualHubs",
      "apiVersion": "2020-05-01",
      "name": "[variables('virtual_hub1_cfg').name]",
      "location": "[parameters('hub1_location')]",
       "dependsOn": [
        "[resourceId('Microsoft.Network/virtualWans', parameters('vWANname'))]"

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.

      • vpnGateway optional
          • id required - string

            Resource ID.

      • p2SVpnGateway optional
          • id required - string

            Resource ID.

      • expressRouteGateway optional
          • id required - string

            Resource ID.

      • azureFirewall optional
          • id required - string

            Resource ID.

      • securityPartnerProvider optional
          • id required - string

            Resource ID.

      • addressPrefix optional - string

        Address-prefix for this VirtualHub.

      • routeTable optional
          • routes optional array
              • addressPrefixes optional - array

                List of all addressPrefixes.

              • nextHopIpAddress optional - string

                NextHop ip address.

      • securityProviderName optional - string

        The Security Provider name.

      • virtualHubRouteTableV2s optional array
          • properties optional
              • routes optional array
                  • destinationType optional - string

                    The type of destinations.

                  • destinations optional - array

                    List of all destinations.

                  • nextHopType optional - string

                    The type of next hops.

                  • nextHops optional - array

                    NextHops ip address.

              • attachedConnections optional - array

                List of all connections attached to this route table v2.

          • name optional - string

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

      • sku optional - string

        The sku of this VirtualHub.

      • routingState optional - string

        The routing state.

      • virtualRouterAsn optional - integer

        VirtualRouter ASN.

      • virtualRouterIps optional - array

        VirtualRouter IPs.

      • allowBranchToBranchTraffic optional - boolean

        Flag to control transit for VirtualRouter hub.

Frequently asked questions

What is Azure Network Virtual Hub?

Azure Network Virtual Hub 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 Virtual Hub?

For Terraform, the SzkolaDevNet/Terraform-Azure-vWAN, zipphreak/azure-vwan-microhack2.0 and mddazure/azure-vwan-microhack source code examples are useful. See the Terraform Example section for further details.

For Azure Resource Manager, the dmauser/azure-hub-spoke-base-lab, naveenpolla/ARM-Templates and s-KaiNet/monaco-csharp-poc source code examples are useful. See the Azure Resource Manager Example section for further details.