Azure Network Gateway

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

azurerm_express_route_gateway (Terraform)

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

Example Usage from GitHub

express_route_gateway.tf#L2
resource "azurerm_express_route_gateway" "er_gateway" {
  depends_on = [azurerm_virtual_hub.vwan_hub]
  count      = var.virtual_hub_config.deploy_er ? 1 : 0

  name                = azurecaf_naming_convention.er_gateway.0.result
  location            = var.location
main.tf#L7
resource "azurerm_express_route_gateway" "this" {
  location            = var.location
  name                = var.name
  resource_group_name = var.resource_group_name
  scale_units         = var.scale_units
  tags                = var.tags
express_route_gateway.tf#L16
resource "azurerm_express_route_gateway" "er_gateway" {
  count = try(var.virtual_hub_config.deploy_er, false) ? 1 : 0

  name                = azurecaf_name.er_gateway.0.result
  location            = var.location
  resource_group_name = var.resource_group_name
express_route_gateway.tf#L2
resource "azurerm_express_route_gateway" "er_gateway" {
  depends_on = [azurerm_virtual_hub.vwan_hub]
  count      = var.virtual_hub_config.deploy_er ? 1 : 0

  name                = azurecaf_naming_convention.er_gateway.0.result
  location            = var.location
express_route_gateway.tf#L16
resource "azurerm_express_route_gateway" "er_gateway" {
  count = try(var.virtual_hub_config.deploy_er, false) ? 1 : 0

  name                = azurecaf_name.er_gateway.0.result
  location            = var.location
  resource_group_name = var.resource_group_name
express_route_gateway.tf#L16
resource "azurerm_express_route_gateway" "er_gateway" {
  depends_on = [azurerm_virtual_hub.vwan_hub]
  count      = var.virtual_hub_config.deploy_er ? 1 : 0

  name                = azurecaf_name.er_gateway.0.result
  location            = var.location
main.tf#L7
resource "azurerm_express_route_gateway" "this" {
  location            = var.location
  name                = var.name
  resource_group_name = var.resource_group_name
  scale_units         = var.scale_units
  tags                = var.tags
main.tf#L26
resource "azurerm_express_route_gateway" "main" {
  for_each            = { for e in var.er_gateway : e.name => e }
  name                = each.value.name
  resource_group_name = var.resource_group_name
  location            = var.resource_group_location
  virtual_hub_id      = azurerm_virtual_hub.main[each.value.region].id
express_route_gateway.tf#L16
resource "azurerm_express_route_gateway" "er_gateway" {
  count = try(var.virtual_hub_config.deploy_er, false) ? 1 : 0

  name                = azurecaf_name.er_gateway.0.result
  location            = var.location
  resource_group_name = var.resource_group_name
express_route_gateway.tf#L2
resource "azurerm_express_route_gateway" "er_gateway" {
  depends_on = [azurerm_virtual_hub.vwan_hub]
  count      = var.virtual_hub_config.deploy_er ? 1 : 0

  name                = azurecaf_naming_convention.er_gateway.0.result
  location            = var.location

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 an ExpressRoute gateway.

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

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

Example Usage from GitHub

ExpressRouteGatewayCreate.json#L9
            "type": "Microsoft.Network/expressRouteGateways",
            "location": "westus",
            "properties": {
                "virtualHub": {
                    "id": "/subscriptions/subid/resourceGroups/resourceGroupId/providers/Microsoft.Network/virtualHubs/virtualHubName"
                },
ExpressRouteGatewayCreate.json#L9
            "type": "Microsoft.Network/expressRouteGateways",
            "location": "westus",
            "properties": {
                "virtualHub": {
                    "id": "/subscriptions/subid/resourceGroups/resourceGroupId/providers/Microsoft.Network/virtualHubs/virtualHubName"
                },
ExpressRouteGatewayCreate.json#L9
            "type": "Microsoft.Network/expressRouteGateways",
            "location": "westus",
            "properties": {
                "virtualHub": {
                    "id": "/subscriptions/subid/resourceGroups/resourceGroupId/providers/Microsoft.Network/virtualHubs/virtualHubName"
                },
ExpressRouteGatewayCreate.json#L9
            "type": "Microsoft.Network/expressRouteGateways",
            "location": "westus",
            "properties": {
                "virtualHub": {
                    "id": "/subscriptions/subid/resourceGroups/resourceGroupId/providers/Microsoft.Network/virtualHubs/virtualHubName"
                },
ExpressRouteGatewayCreate.json#L9
            "type": "Microsoft.Network/expressRouteGateways",
            "location": "westus",
            "properties": {
                "virtualHub": {
                    "id": "/subscriptions/subid/resourceGroups/resourceGroupId/providers/Microsoft.Network/virtualHubs/virtualHubName"
                },
ExpressRouteGatewayCreate.json#L9
            "type": "Microsoft.Network/expressRouteGateways",
            "location": "westus",
            "properties": {
                "virtualHub": {
                    "id": "/subscriptions/subid/resourceGroups/resourceGroupId/providers/Microsoft.Network/virtualHubs/virtualHubName"
                },
ExpressRouteGatewayCreate.json#L9
            "type": "Microsoft.Network/expressRouteGateways",
            "location": "westus",
            "properties": {
                "virtualHub": {
                    "id": "/subscriptions/subid/resourceGroups/resourceGroupId/providers/Microsoft.Network/virtualHubs/virtualHubName"
                },
ExpressRouteGatewayCreate.json#L9
            "type": "Microsoft.Network/expressRouteGateways",
            "location": "westus",
            "properties": {
                "virtualHub": {
                    "id": "/subscriptions/subid/resourceGroups/resourceGroupId/providers/Microsoft.Network/virtualHubs/virtualHubName"
                },
ExpressRouteGatewayCreate.json#L9
            "type": "Microsoft.Network/expressRouteGateways",
            "location": "westus",
            "properties": {
                "virtualHub": {
                    "id": "/subscriptions/subid/resourceGroups/resourceGroupId/providers/Microsoft.Network/virtualHubs/virtualHubName"
                },
ExpressRouteGatewayCreate.json#L9
            "type": "Microsoft.Network/expressRouteGateways",
            "location": "westus",
            "properties": {
                "virtualHub": {
                    "id": "/subscriptions/subid/resourceGroups/resourceGroupId/providers/Microsoft.Network/virtualHubs/virtualHubName"
                },

Parameters

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

    Resource location.

  • tags optional - string

    Resource tags.

  • properties required
      • autoScaleConfiguration optional
          • bounds optional
              • min optional - integer

                Minimum number of scale units deployed for ExpressRoute gateway.

              • max optional - integer

                Maximum number of scale units deployed for ExpressRoute gateway.

      • virtualHub required
          • id required - string

            Resource ID.

Frequently asked questions

What is Azure Network Gateway?

Azure Network Gateway 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 Gateway?

For Terraform, the tushar7653/testcaf, kevinhead/azurerm and anmoltoppo/Terraform source code examples are useful. See the Terraform Example section for further details.

For Azure Resource Manager, the sanjaypavan/OldAzure-Rest-API, shawns1/shawns1CI and shawns1/shawns1CI source code examples are useful. See the Azure Resource Manager Example section for further details.