Skip to content

claranet/terraform-azurerm-vnet-peering

Repository files navigation

Azure Virtual Network Peering

Changelog Notice Apache V2 License TF Registry

Terraform module to generate a Virtual Network Peering between two Virtual Networks which can belong to two different Azure Subscriptions.

Limitations

  • Peering between two virtual networks in different tenants isn't possible.

Global versioning rule for Claranet Azure modules

Module version Terraform version AzureRM version
>= 7.x.x 1.3.x >= 3.0
>= 6.x.x 1.x >= 3.0
>= 5.x.x 0.15.x >= 2.0
>= 4.x.x 0.13.x / 0.14.x >= 2.0
>= 3.x.x 0.12.x >= 2.0
>= 2.x.x 0.12.x < 2.0
< 2.x.x 0.11.x < 2.0

Contributing

If you want to contribute to this repository, feel free to use our pre-commit git hook configuration which will help you automatically update and format some files for you by enforcing our Terraform code module best-practices.

More details are available in the CONTRIBUTING.md file.

Usage

This module is optimized to work with the Claranet terraform-wrapper tool which set some terraform variables in the environment needed by this module. More details about variables set by the terraform-wrapper available in the documentation.

provider "azurerm" {
  subscription_id = var.azure_subscription_id
  tenant_id       = var.azure_tenant_id

  features {}
}
provider "azurerm" {
  alias           = "preprod"
  subscription_id = var.preprod_subscription_id
  tenant_id       = var.azure_tenant_id

  features {}
}

module "azure_region" {
  source  = "claranet/regions/azurerm"
  version = "x.x.x"

  azure_region = var.azure_region
}

module "rg" {
  source  = "claranet/rg/azurerm"
  version = "x.x.x"

  location    = module.azure_region.location
  client_name = var.client_name
  environment = var.environment
  stack       = var.stack
}

module "azure_virtual_network" {
  source  = "claranet/vnet/azurerm"
  version = "x.x.x"

  environment    = var.environment
  location       = module.azure_region.location
  location_short = module.azure_region.location_short
  client_name    = var.client_name
  stack          = var.stack

  resource_group_name = module.rg.resource_group_name

  vnet_cidr   = ["10.10.0.0/16"]
  dns_servers = ["10.0.0.4", "10.0.0.5"] # Can be empty if not used
}

module "azure_vnet_peering" {
  source  = "claranet/vnet-peering/azurerm"
  version = "x.x.x"

  providers = {
    azurerm.src = azurerm
    azurerm.dst = azurerm.preprod
  }

  vnet_src_id  = module.azure_virtual_network.virtual_network_id
  vnet_dest_id = var.virtual_network_id_dest

  allow_forwarded_src_traffic  = true
  allow_forwarded_dest_traffic = true

  allow_virtual_src_network_access  = true
  allow_virtual_dest_network_access = true
}

Providers

Name Version
azurecaf ~> 1.2, >= 1.2.22
azurerm.dst >= 2.0
azurerm.src >= 2.0

Modules

No modules.

Resources

Name Type
azurerm_virtual_network_peering.peering_dest resource
azurerm_virtual_network_peering.peering_src resource
azurecaf_name.vnet_peering_dst data source
azurecaf_name.vnet_peering_src data source

Inputs

Name Description Type Default Required
allow_forwarded_dest_traffic Option allow_forwarded_traffic for the dest vnet to peer. Controls if forwarded traffic from VMs in the remote virtual network is allowed. Defaults to false. https://www.terraform.io/docs/providers/azurerm/r/virtual_network_peering.html#allow_forwarded_traffic bool false no
allow_forwarded_src_traffic Option allow_forwarded_traffic for the src vnet to peer. Controls if forwarded traffic from VMs in the remote virtual network is allowed. Defaults to false. https://www.terraform.io/docs/providers/azurerm/r/virtual_network_peering.html#allow_forwarded_traffic bool false no
allow_gateway_dest_transit Option allow_gateway_transit for the dest vnet to peer. Controls gatewayLinks can be used in the remote virtual network’s link to the local virtual network. https://www.terraform.io/docs/providers/azurerm/r/virtual_network_peering.html#allow_gateway_transit bool false no
allow_gateway_src_transit Option allow_gateway_transit for the src vnet to peer. Controls gatewayLinks can be used in the remote virtual network’s link to the local virtual network. https://www.terraform.io/docs/providers/azurerm/r/virtual_network_peering.html#allow_gateway_transit bool false no
allow_virtual_dest_network_access Option allow_virtual_network_access for the dest vnet to peer. Controls if the VMs in the remote virtual network can access VMs in the local virtual network. Defaults to false. https://www.terraform.io/docs/providers/azurerm/r/virtual_network_peering.html#allow_virtual_network_access bool false no
allow_virtual_src_network_access Option allow_virtual_network_access for the src vnet to peer. Controls if the VMs in the remote virtual network can access VMs in the local virtual network. Defaults to false. https://www.terraform.io/docs/providers/azurerm/r/virtual_network_peering.html#allow_virtual_network_access bool false no
custom_peering_dst_name Custom name of the vnet peerings to create string "" no
custom_peering_src_name Custom name of the vnet peerings to create string "" no
name_prefix Optional prefix for the generated name string "" no
name_suffix Optional suffix for the generated name string "to" no
use_caf_naming Use the Azure CAF naming provider to generate default resource name. custom_rg_name override this if set. Legacy default name is used if this is set to false. bool true no
use_remote_dest_gateway Option use_remote_gateway for the dest vnet to peer. Controls if remote gateways can be used on the local virtual network. https://www.terraform.io/docs/providers/azurerm/r/virtual_network_peering.html#use_remote_gateways bool false no
use_remote_src_gateway Option use_remote_gateway for the src vnet to peer. Controls if remote gateways can be used on the local virtual network. https://www.terraform.io/docs/providers/azurerm/r/virtual_network_peering.html#use_remote_gateways bool false no
vnet_dest_id ID of the dest vnet to peer string n/a yes
vnet_src_id ID of the src vnet to peer string n/a yes

Outputs

Name Description
vnet_peering_dest_id Virtual network dest peering id
vnet_peering_dest_name Virtual network dest peering name
vnet_peering_src_id Virtual network src peering id
vnet_peering_src_name Virtual network src peering name

Related documentation

Terraform resource documentation: terraform.io/docs/providers/azurerm/r/virtual_network_peering.html

Microsoft Azure documentation: docs.microsoft.com/en-us/azure/virtual-network/virtual-network-peering-overview