azurestack_virtual_network_gateway_connection

Manages a connection in an existing Virtual Network Gateway.

Example Usage

Site-to-Site connection

The following example shows a connection between an Azure virtual network and an on-premises VPN device and network.

resource "azurestack_resource_group" "test" {
  name     = "test"
  location = "West US"
}

resource "azurestack_virtual_network" "test" {
  name                = "test"
  location            = azurestack_resource_group.test.location
  resource_group_name = azurestack_resource_group.test.name
  address_space       = ["10.0.0.0/16"]
}

resource "azurestack_subnet" "test" {
  name                 = "GatewaySubnet"
  resource_group_name  = azurestack_resource_group.test.name
  virtual_network_name = azurestack_virtual_network.test.name
  address_prefix       = "10.0.1.0/24"
}

resource "azurestack_local_network_gateway" "onpremise" {
  name                = "onpremise"
  location            = azurestack_resource_group.test.location
  resource_group_name = azurestack_resource_group.test.name
  gateway_address     = "168.62.225.23"
  address_space       = ["10.1.1.0/24"]
}

resource "azurestack_public_ip" "test" {
  name                         = "test"
  location                     = azurestack_resource_group.test.location
  resource_group_name          = azurestack_resource_group.test.name
  public_ip_address_allocation = "Dynamic"
}

resource "azurestack_virtual_network_gateway" "test" {
  name                = "test"
  location            = azurestack_resource_group.test.location
  resource_group_name = azurestack_resource_group.test.name

  type     = "Vpn"
  vpn_type = "RouteBased"

  active_active = false
  enable_bgp    = false
  sku           = "Basic"

  ip_configuration {
    public_ip_address_id          = azurestack_public_ip.test.id
    private_ip_address_allocation = "Dynamic"
    subnet_id                     = azurestack_subnet.test.id
  }
}

resource "azurestack_virtual_network_gateway_connection" "onpremise" {
  name                = "onpremise"
  location            = azurestack_resource_group.test.location
  resource_group_name = azurestack_resource_group.test.name

  type                       = "IPsec"
  virtual_network_gateway_id = azurestack_virtual_network_gateway.test.id
  local_network_gateway_id   = azurestack_local_network_gateway.onpremise.id

  shared_key = "4-v3ry-53cr37-1p53c-5h4r3d-k3y"
}

VNet-to-VNet connection

The following example shows a connection between two Azure virtual network in different locations/regions.

resource "azurestack_resource_group" "example" {
  name     = "us"
  location = "East US"
}

resource "azurestack_virtual_network" "example" {
  name                = "example"
  location            = azurestack_resource_group.example.location
  resource_group_name = azurestack_resource_group.example.name
  address_space       = ["10.0.0.0/16"]
}

resource "azurestack_subnet" "example" {
  name                 = "GatewaySubnet"
  resource_group_name  = azurestack_resource_group.example.name
  virtual_network_name = azurestack_virtual_network.example.name
  address_prefix       = "10.0.1.0/24"
}

resource "azurestack_public_ip" "example" {
  name                = "example"
  location            = azurestack_resource_group.example.location
  resource_group_name = azurestack_resource_group.example.name
  allocation_method   = "Dynamic"
}

resource "azurestack_virtual_network_gateway" "example" {
  name                = "example"
  location            = azurestack_resource_group.example.location
  resource_group_name = azurestack_resource_group.example.name

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

  ip_configuration {
    name                          = "vnetGatewayConfig"
    public_ip_address_id          = azurestack_public_ip.example.id
    private_ip_address_allocation = "Dynamic"
    subnet_id                     = azurestack_subnet.example.id
  }
}

resource "azurestack_local_network_gateway" "example" {
  name                = "example"
  location            = azurestack_resource_group.example.location
  resource_group_name = azurestack_resource_group.example.name

  gateway_address = "168.62.225.12"
  address_space   = ["10.1.1.0/24"]
}

resource "azurestack_virtual_network_gateway_connection" "test" {
  name                = "example"
  location            = azurestack_resource_group.example.location
  resource_group_name = azurestack_resource_group.example.name

  type                       = "IPsec"
  virtual_network_gateway_id = azurestack_virtual_network_gateway.example.id
  local_network_gateway_id   = azurestack_local_network_gateway.example.id

  shared_key = "4-v3ry-53cr37-1p53c-5h4r3d-k3y"
}

Argument Reference

The following arguments are supported:

Attributes Reference

The following attributes are exported:

Import

Virtual Network Gateway Connections can be imported using their resource id, e.g.

terraform import azurestack_virtual_network_gateway_connection.testConnection /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myGroup1/providers/Microsoft.Network/connections/myConnection1