azurerm_virtual_network_gateway_nat_rule

Manages a Virtual Network Gateway Nat Rule.

Example Usage

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

resource "azurerm_virtual_network" "example" {
  name                = "example-vnet"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  address_space       = ["10.0.0.0/16"]
}

resource "azurerm_subnet" "example" {
  name                 = "GatewaySubnet"
  resource_group_name  = azurerm_resource_group.example.name
  virtual_network_name = azurerm_virtual_network.example.name
  address_prefixes     = ["10.0.1.0/24"]
}

resource "azurerm_public_ip" "example" {
  name                = "example-pip"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  allocation_method   = "Dynamic"
}

resource "azurerm_virtual_network_gateway" "example" {
  name                = "example-vnetgw"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name

  type     = "Vpn"
  vpn_type = "RouteBased"
  sku      = "Basic"

  ip_configuration {
    public_ip_address_id          = azurerm_public_ip.example.id
    private_ip_address_allocation = "Dynamic"
    subnet_id                     = azurerm_subnet.example.id
  }
}

data "azurerm_virtual_network_gateway" "example" {
  name                = azurerm_virtual_network_gateway.example.name
  resource_group_name = azurerm_virtual_network_gateway.example.resource_group_name
}

resource "azurerm_virtual_network_gateway_nat_rule" "example" {
  name                       = "example-vnetgwnatrule"
  resource_group_name        = azurerm_resource_group.example.name
  virtual_network_gateway_id = data.azurerm_virtual_network_gateway.example.id
  mode                       = "EgressSnat"
  type                       = "Dynamic"
  ip_configuration_id        = data.azurerm_virtual_network_gateway.example.ip_configuration[0].id

  external_mapping {
    address_space = "10.2.0.0/26"
    port_range    = "200"
  }

  internal_mapping {
    address_space = "10.4.0.0/26"
    port_range    = "400"
  }
}

Arguments Reference

The following arguments are supported:


A external_mapping block exports the following:


A internal_mapping block exports the following:


Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

Import

Virtual Network Gateway Nat Rules can be imported using the resource id, e.g.

terraform import azurerm_virtual_network_gateway_nat_rule.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/virtualNetworkGateways/gw1/natRules/rule1