Azure Network Circuit Peering
This page shows how to write Terraform and Azure Resource Manager for Network Circuit Peering and write them securely.
azurerm_express_route_circuit_peering (Terraform)
The Circuit Peering in Network can be configured in Terraform with the resource name azurerm_express_route_circuit_peering. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_express_route_circuit_peering" "Hub-ExpressRoute-Peering" {
peering_type = var.ExpressRoute-PeeringType
express_route_circuit_name = var.ExpressRoute-CircuitName
resource_group_name = var.ExpressRoute-RGName
peer_asn = var.PeerASN
primary_peer_address_prefix = var.PrimaryPeerAddressPrefix
resource "azurerm_express_route_circuit_peering" "Hub-ExpressRoute-Peering" {
peering_type = var.ExpressRoute-PeeringType
express_route_circuit_name = var.ExpressRoute-CircuitName
resource_group_name = var.ExpressRoute-RGName
peer_asn = var.PeerASN
primary_peer_address_prefix = var.PrimaryPeerAddressPrefix
resource "azurerm_express_route_circuit_peering" "cloudN" {
peering_type = "AzurePrivatePeering"
express_route_circuit_name = azurerm_express_route_circuit.cloudN.name
resource_group_name = "s5-vnet-rg-01"
peer_asn = 65000 # on prem router ASN
primary_peer_address_prefix = "10.255.255.20/30" # IP prefix for ER
resource "azurerm_express_route_circuit_peering" "Hub-ExpressRoute-Peering" {
peering_type = var.ExpressRoute-PeeringType
express_route_circuit_name = var.ExpressRoute-CircuitName
resource_group_name = var.ExpressRoute-RGName
peer_asn = var.PeerASN
primary_peer_address_prefix = var.PrimaryPeerAddressPrefix
resource "azurerm_express_route_circuit_peering" "this" {
express_route_circuit_name = var.express_route_circuit_name
peer_asn = var.peer_asn
peering_type = var.peering_type
primary_peer_address_prefix = var.primary_peer_address_prefix
resource_group_name = var.resource_group_name
resource "azurerm_express_route_circuit_peering" "this" {
express_route_circuit_name = var.express_route_circuit_name
peer_asn = var.peer_asn
peering_type = var.peering_type
primary_peer_address_prefix = var.primary_peer_address_prefix
resource_group_name = var.resource_group_name
resource "azurerm_express_route_circuit_peering" "example" {
peering_type = "AzurePrivatePeering"
express_route_circuit_name = azurerm_express_route_circuit.example.name
resource_group_name = azurerm_resource_group.example.name
shared_key = "ItsASecret"
peer_asn = 100
resource "azurerm_express_route_circuit_peering" "ercprivatepeer" {
for_each = var.express_route_enabled && var.express_route_private_peering_enabled ? toset(["express_route"]) : toset([])
resource_group_name = var.resource_group_name
express_route_circuit_name = azurerm_express_route_circuit.erc["express_route"].name
peering_type = "AzurePrivatePeering"
primary_peer_address_prefix = var.express_route_circuit_private_peering_primary_peer_address_prefix
resource "azurerm_express_route_circuit_peering" "example" {
peering_type = "AzurePrivatePeering"
# Acceptable values include AzurePrivatePeering, AzurePublicPeering and MicrosoftPeering
express_route_circuit_name = var.express_route_circuit_name
resource_group_name = var.rg_name
peer_asn = var.peer_asn
resource "azurerm_express_route_circuit_peering" "local" {
count = var.configure_er_private_peering ? 1 : 0
peering_type = "AzurePrivatePeering"
express_route_circuit_name = azurerm_express_route_circuit.local.name
resource_group_name = var.resource_group_name
peer_asn = var.express_route_definitions.azure_private_peering.peer_asn
Parameters
-
azure_asnoptional computed - number -
express_route_circuit_namerequired - string -
idoptional computed - string -
peer_asnoptional computed - number -
peering_typerequired - string -
primary_azure_portoptional computed - string -
primary_peer_address_prefixrequired - string -
resource_group_namerequired - string -
route_filter_idoptional - string -
secondary_azure_portoptional computed - string -
secondary_peer_address_prefixrequired - string -
shared_keyoptional - string -
vlan_idrequired - number -
ipv6list block-
primary_peer_address_prefixrequired - string -
route_filter_idoptional - string -
secondary_peer_address_prefixrequired - string -
microsoft_peeringlist block-
advertised_public_prefixesoptional - list of string -
customer_asnoptional - number -
routing_registry_nameoptional - string
-
-
-
microsoft_peering_configlist block-
advertised_public_prefixesrequired - list of string -
customer_asnoptional - number -
routing_registry_nameoptional - string
-
-
timeoutssingle block
Explanation in Terraform Registry
Manages an ExpressRoute Circuit Peering.
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.
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.
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.
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.
Microsoft.Network/expressRouteCircuits/peerings (Azure Resource Manager)
The expressRouteCircuits/peerings in Microsoft.Network can be configured in Azure Resource Manager with the resource name Microsoft.Network/expressRouteCircuits/peerings. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
An example could not be found in GitHub.
Parameters
namerequired - stringtyperequired - stringapiVersionrequired - stringpropertiesrequiredpeeringTypeoptional - stringThe peering type.
stateoptional - stringThe peering state.
peerASNoptional - integerThe peer ASN.
primaryPeerAddressPrefixoptional - stringThe primary address prefix.
secondaryPeerAddressPrefixoptional - stringThe secondary address prefix.
sharedKeyoptional - stringThe shared key.
vlanIdoptional - integerThe VLAN ID.
microsoftPeeringConfigoptionaladvertisedPublicPrefixesoptional - arrayThe reference to AdvertisedPublicPrefixes.
advertisedCommunitiesoptional - arrayThe communities of bgp peering. Specified for microsoft peering.
legacyModeoptional - integerThe legacy mode of the peering.
customerASNoptional - integerThe CustomerASN of the peering.
routingRegistryNameoptional - stringThe RoutingRegistryName of the configuration.
statsoptionalprimarybytesInoptional - integerThe Primary BytesIn of the peering.
primarybytesOutoptional - integerThe primary BytesOut of the peering.
secondarybytesInoptional - integerThe secondary BytesIn of the peering.
secondarybytesOutoptional - integerThe secondary BytesOut of the peering.
gatewayManagerEtagoptional - stringThe GatewayManager Etag.
routeFilteroptionalidrequired - stringResource ID.
ipv6PeeringConfigoptionalprimaryPeerAddressPrefixoptional - stringThe primary address prefix.
secondaryPeerAddressPrefixoptional - stringThe secondary address prefix.
microsoftPeeringConfigoptionaladvertisedPublicPrefixesoptional - arrayThe reference to AdvertisedPublicPrefixes.
advertisedCommunitiesoptional - arrayThe communities of bgp peering. Specified for microsoft peering.
legacyModeoptional - integerThe legacy mode of the peering.
customerASNoptional - integerThe CustomerASN of the peering.
routingRegistryNameoptional - stringThe RoutingRegistryName of the configuration.
routeFilteroptionalidrequired - stringResource ID.
stateoptional - stringThe state of peering.
expressRouteConnectionoptionalidrequired - stringResource ID.
Frequently asked questions
What is Azure Network Circuit Peering?
Azure Network Circuit Peering 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 Circuit Peering?
For Terraform, the AErmie/Terraform-Real-World-Edition, AErmie/TFCloud-IaC-Using-Terraform and karolnedza/migration source code examples are useful. See the Terraform Example section for further details.