Virtual Network Peerings - Create Or Update

Creates or updates a peering in the specified virtual network.

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/virtualNetworkPeerings/{virtualNetworkPeeringName}?api-version=2023-09-01
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/virtualNetworkPeerings/{virtualNetworkPeeringName}?syncRemoteAddressSpace=true&api-version=2023-09-01

URI Parameters

Name In Required Type Description
resourceGroupName
path True

string

The name of the resource group.

subscriptionId
path True

string

The subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription ID forms part of the URI for every service call.

virtualNetworkName
path True

string

The name of the virtual network.

virtualNetworkPeeringName
path True

string

The name of the peering.

api-version
query True

string

Client API version.

syncRemoteAddressSpace
query

SyncRemoteAddressSpace

Parameter indicates the intention to sync the peering with the current address space on the remote vNet after it's updated.

Request Body

Name Type Description
id

string

Resource ID.

name

string

The name of the resource that is unique within a resource group. This name can be used to access the resource.

properties.allowForwardedTraffic

boolean

Whether the forwarded traffic from the VMs in the local virtual network will be allowed/disallowed in remote virtual network.

properties.allowGatewayTransit

boolean

If gateway links can be used in remote virtual networking to link to this virtual network.

properties.allowVirtualNetworkAccess

boolean

Whether the VMs in the local virtual network space would be able to access the VMs in remote virtual network space.

properties.doNotVerifyRemoteGateways

boolean

If we need to verify the provisioning state of the remote gateway.

properties.peeringState

VirtualNetworkPeeringState

The status of the virtual network peering.

properties.peeringSyncLevel

VirtualNetworkPeeringLevel

The peering sync status of the virtual network peering.

properties.remoteAddressSpace

AddressSpace

The reference to the address space peered with the remote virtual network.

properties.remoteBgpCommunities

VirtualNetworkBgpCommunities

The reference to the remote virtual network's Bgp Communities.

properties.remoteVirtualNetwork

SubResource

The reference to the remote virtual network. The remote virtual network can be in the same or different region (preview). See here to register for the preview and learn more (https://docs.microsoft.com/en-us/azure/virtual-network/virtual-network-create-peering).

properties.remoteVirtualNetworkAddressSpace

AddressSpace

The reference to the current address space of the remote virtual network.

properties.useRemoteGateways

boolean

If remote gateways can be used on this virtual network. If the flag is set to true, and allowGatewayTransit on remote peering is also true, virtual network will use gateways of remote virtual network for transit. Only one peering can have this flag set to true. This flag cannot be set if virtual network already has a gateway.

type

string

Resource type.

Responses

Name Type Description
200 OK

VirtualNetworkPeering

Update successful. The operation returns the resulting VirtualNetworkPeering resource.

201 Created

VirtualNetworkPeering

Create successful. The operation returns the resulting VirtualNetworkPeering resource.

Other Status Codes

CloudError

Error response describing why the operation failed.

Security

azure_auth

Azure Active Directory OAuth2 Flow.

Type: oauth2
Flow: implicit
Authorization URL: https://login.microsoftonline.com/common/oauth2/authorize

Scopes

Name Description
user_impersonation impersonate your user account

Examples

Create peering
Create peering with remote virtual network encryption
Sync Peering

Create peering

Sample Request

PUT https://management.azure.com/subscriptions/subid/resourceGroups/peerTest/providers/Microsoft.Network/virtualNetworks/vnet1/virtualNetworkPeerings/peer?syncRemoteAddressSpace=true&api-version=2023-09-01

{
  "properties": {
    "allowVirtualNetworkAccess": true,
    "allowForwardedTraffic": true,
    "allowGatewayTransit": false,
    "useRemoteGateways": false,
    "remoteVirtualNetwork": {
      "id": "/subscriptions/subid/resourceGroups/peerTest/providers/Microsoft.Network/virtualNetworks/vnet2"
    }
  }
}

Sample Response

{
  "id": "/subscriptions/subid/resourceGroups/peerTest/providers/Microsoft.Network/virtualNetworks/vnet1/virtualNetworkPeerings/peer",
  "name": "peer",
  "properties": {
    "allowVirtualNetworkAccess": true,
    "allowForwardedTraffic": true,
    "allowGatewayTransit": false,
    "useRemoteGateways": false,
    "remoteVirtualNetwork": {
      "id": "/subscriptions/subid/resourceGroups/peerTest/providers/Microsoft.Network/virtualNetworks/vnet2"
    },
    "remoteAddressSpace": {
      "addressPrefixes": [
        "12.0.0.0/8"
      ]
    },
    "remoteVirtualNetworkAddressSpace": {
      "addressPrefixes": [
        "12.0.0.0/8"
      ]
    },
    "remoteBgpCommunities": {
      "virtualNetworkCommunity": "12076:20002",
      "regionalCommunity": "12076:50004"
    },
    "peeringState": "Initiated",
    "peeringSyncLevel": "FullyInSync",
    "provisioningState": "Succeeded"
  }
}
{
  "id": "/subscriptions/subid/resourceGroups/peerTest/providers/Microsoft.Network/virtualNetworks/vnet1/virtualNetworkPeerings/peer",
  "name": "peer",
  "properties": {
    "allowVirtualNetworkAccess": true,
    "allowForwardedTraffic": true,
    "allowGatewayTransit": false,
    "useRemoteGateways": false,
    "remoteVirtualNetwork": {
      "id": "/subscriptions/subid/resourceGroups/peerTest/providers/Microsoft.Network/virtualNetworks/vnet2"
    },
    "remoteAddressSpace": {
      "addressPrefixes": [
        "12.0.0.0/8"
      ]
    },
    "remoteVirtualNetworkAddressSpace": {
      "addressPrefixes": [
        "12.0.0.0/8"
      ]
    },
    "remoteBgpCommunities": {
      "virtualNetworkCommunity": "12076:20002",
      "regionalCommunity": "12076:50004"
    },
    "peeringState": "Initiated",
    "peeringSyncLevel": "FullyInSync",
    "provisioningState": "Succeeded"
  }
}

Create peering with remote virtual network encryption

Sample Request

PUT https://management.azure.com/subscriptions/subid/resourceGroups/peerTest/providers/Microsoft.Network/virtualNetworks/vnet1/virtualNetworkPeerings/peer?syncRemoteAddressSpace=true&api-version=2023-09-01

{
  "properties": {
    "allowVirtualNetworkAccess": true,
    "allowForwardedTraffic": true,
    "allowGatewayTransit": false,
    "useRemoteGateways": false,
    "remoteVirtualNetwork": {
      "id": "/subscriptions/subid/resourceGroups/peerTest/providers/Microsoft.Network/virtualNetworks/vnet2"
    }
  }
}

Sample Response

{
  "id": "/subscriptions/subid/resourceGroups/peerTest/providers/Microsoft.Network/virtualNetworks/vnet1/virtualNetworkPeerings/peer",
  "name": "peer",
  "properties": {
    "allowVirtualNetworkAccess": true,
    "allowForwardedTraffic": true,
    "allowGatewayTransit": false,
    "useRemoteGateways": false,
    "remoteVirtualNetwork": {
      "id": "/subscriptions/subid/resourceGroups/peerTest/providers/Microsoft.Network/virtualNetworks/vnet2"
    },
    "remoteAddressSpace": {
      "addressPrefixes": [
        "12.0.0.0/8"
      ]
    },
    "remoteBgpCommunities": {
      "virtualNetworkCommunity": "12076:20002",
      "regionalCommunity": "12076:50004"
    },
    "remoteVirtualNetworkEncryption": {
      "enabled": true,
      "enforcement": "AllowUnencrypted"
    },
    "peeringState": "Initiated",
    "provisioningState": "Succeeded"
  }
}
{
  "id": "/subscriptions/subid/resourceGroups/peerTest/providers/Microsoft.Network/virtualNetworks/vnet1/virtualNetworkPeerings/peer",
  "name": "peer",
  "properties": {
    "allowVirtualNetworkAccess": true,
    "allowForwardedTraffic": true,
    "allowGatewayTransit": false,
    "useRemoteGateways": false,
    "remoteVirtualNetwork": {
      "id": "/subscriptions/subid/resourceGroups/peerTest/providers/Microsoft.Network/virtualNetworks/vnet2"
    },
    "remoteAddressSpace": {
      "addressPrefixes": [
        "12.0.0.0/8"
      ]
    },
    "remoteBgpCommunities": {
      "virtualNetworkCommunity": "12076:20002",
      "regionalCommunity": "12076:50004"
    },
    "remoteVirtualNetworkEncryption": {
      "enabled": true,
      "enforcement": "AllowUnencrypted"
    },
    "peeringState": "Initiated",
    "provisioningState": "Succeeded"
  }
}

Sync Peering

Sample Request

PUT https://management.azure.com/subscriptions/subid/resourceGroups/peerTest/providers/Microsoft.Network/virtualNetworks/vnet1/virtualNetworkPeerings/peer?syncRemoteAddressSpace=true&api-version=2023-09-01

{
  "properties": {
    "allowVirtualNetworkAccess": true,
    "allowForwardedTraffic": true,
    "allowGatewayTransit": false,
    "useRemoteGateways": false,
    "remoteVirtualNetwork": {
      "id": "/subscriptions/subid/resourceGroups/peerTest/providers/Microsoft.Network/virtualNetworks/vnet2"
    }
  }
}

Sample Response

{
  "id": "/subscriptions/subid/resourceGroups/peerTest/providers/Microsoft.Network/virtualNetworks/vnet1/virtualNetworkPeerings/peer",
  "name": "peer",
  "properties": {
    "allowVirtualNetworkAccess": true,
    "allowForwardedTraffic": true,
    "allowGatewayTransit": false,
    "useRemoteGateways": false,
    "remoteVirtualNetwork": {
      "id": "/subscriptions/subid/resourceGroups/peerTest/providers/Microsoft.Network/virtualNetworks/vnet2"
    },
    "remoteAddressSpace": {
      "addressPrefixes": [
        "12.0.0.0/8"
      ]
    },
    "remoteVirtualNetworkAddressSpace": {
      "addressPrefixes": [
        "12.0.0.0/8"
      ]
    },
    "remoteBgpCommunities": {
      "virtualNetworkCommunity": "12076:20002",
      "regionalCommunity": "12076:50004"
    },
    "peeringState": "Initiated",
    "peeringSyncLevel": "FullyInSync",
    "provisioningState": "Succeeded"
  }
}
{
  "id": "/subscriptions/subid/resourceGroups/peerTest/providers/Microsoft.Network/virtualNetworks/vnet1/virtualNetworkPeerings/peer",
  "name": "peer",
  "properties": {
    "allowVirtualNetworkAccess": true,
    "allowForwardedTraffic": true,
    "allowGatewayTransit": false,
    "useRemoteGateways": false,
    "remoteVirtualNetwork": {
      "id": "/subscriptions/subid/resourceGroups/peerTest/providers/Microsoft.Network/virtualNetworks/vnet2"
    },
    "remoteAddressSpace": {
      "addressPrefixes": [
        "12.0.0.0/8"
      ]
    },
    "remoteVirtualNetworkAddressSpace": {
      "addressPrefixes": [
        "12.0.0.0/8"
      ]
    },
    "remoteBgpCommunities": {
      "virtualNetworkCommunity": "12076:20002",
      "regionalCommunity": "12076:50004"
    },
    "peeringState": "Initiated",
    "peeringSyncLevel": "FullyInSync",
    "provisioningState": "Succeeded"
  }
}

Definitions

Name Description
AddressSpace

AddressSpace contains an array of IP address ranges that can be used by subnets of the virtual network.

CloudError

An error response from the service.

CloudErrorBody

An error response from the service.

ProvisioningState

The current provisioning state.

SubResource

Reference to another subresource.

SyncRemoteAddressSpace

Parameter indicates the intention to sync the peering with the current address space on the remote vNet after it's updated.

VirtualNetworkBgpCommunities

Bgp Communities sent over ExpressRoute with each route corresponding to a prefix in this VNET.

VirtualNetworkEncryption

Indicates if encryption is enabled on virtual network and if VM without encryption is allowed in encrypted VNet.

VirtualNetworkEncryptionEnforcement

If the encrypted VNet allows VM that does not support encryption

VirtualNetworkPeering

Peerings in a virtual network resource.

VirtualNetworkPeeringLevel

The peering sync status of the virtual network peering.

VirtualNetworkPeeringState

The status of the virtual network peering.

AddressSpace

AddressSpace contains an array of IP address ranges that can be used by subnets of the virtual network.

Name Type Description
addressPrefixes

string[]

A list of address blocks reserved for this virtual network in CIDR notation.

CloudError

An error response from the service.

Name Type Description
error

CloudErrorBody

Cloud error body.

CloudErrorBody

An error response from the service.

Name Type Description
code

string

An identifier for the error. Codes are invariant and are intended to be consumed programmatically.

details

CloudErrorBody[]

A list of additional details about the error.

message

string

A message describing the error, intended to be suitable for display in a user interface.

target

string

The target of the particular error. For example, the name of the property in error.

ProvisioningState

The current provisioning state.

Name Type Description
Deleting

string

Failed

string

Succeeded

string

Updating

string

SubResource

Reference to another subresource.

Name Type Description
id

string

Resource ID.

SyncRemoteAddressSpace

Parameter indicates the intention to sync the peering with the current address space on the remote vNet after it's updated.

Name Type Description
true

string

VirtualNetworkBgpCommunities

Bgp Communities sent over ExpressRoute with each route corresponding to a prefix in this VNET.

Name Type Description
regionalCommunity

string

The BGP community associated with the region of the virtual network.

virtualNetworkCommunity

string

The BGP community associated with the virtual network.

VirtualNetworkEncryption

Indicates if encryption is enabled on virtual network and if VM without encryption is allowed in encrypted VNet.

Name Type Description
enabled

boolean

Indicates if encryption is enabled on the virtual network.

enforcement

VirtualNetworkEncryptionEnforcement

If the encrypted VNet allows VM that does not support encryption

VirtualNetworkEncryptionEnforcement

If the encrypted VNet allows VM that does not support encryption

Name Type Description
AllowUnencrypted

string

DropUnencrypted

string

VirtualNetworkPeering

Peerings in a virtual network resource.

Name Type Description
etag

string

A unique read-only string that changes whenever the resource is updated.

id

string

Resource ID.

name

string

The name of the resource that is unique within a resource group. This name can be used to access the resource.

properties.allowForwardedTraffic

boolean

Whether the forwarded traffic from the VMs in the local virtual network will be allowed/disallowed in remote virtual network.

properties.allowGatewayTransit

boolean

If gateway links can be used in remote virtual networking to link to this virtual network.

properties.allowVirtualNetworkAccess

boolean

Whether the VMs in the local virtual network space would be able to access the VMs in remote virtual network space.

properties.doNotVerifyRemoteGateways

boolean

If we need to verify the provisioning state of the remote gateway.

properties.peeringState

VirtualNetworkPeeringState

The status of the virtual network peering.

properties.peeringSyncLevel

VirtualNetworkPeeringLevel

The peering sync status of the virtual network peering.

properties.provisioningState

ProvisioningState

The provisioning state of the virtual network peering resource.

properties.remoteAddressSpace

AddressSpace

The reference to the address space peered with the remote virtual network.

properties.remoteBgpCommunities

VirtualNetworkBgpCommunities

The reference to the remote virtual network's Bgp Communities.

properties.remoteVirtualNetwork

SubResource

The reference to the remote virtual network. The remote virtual network can be in the same or different region (preview). See here to register for the preview and learn more (https://docs.microsoft.com/en-us/azure/virtual-network/virtual-network-create-peering).

properties.remoteVirtualNetworkAddressSpace

AddressSpace

The reference to the current address space of the remote virtual network.

properties.remoteVirtualNetworkEncryption

VirtualNetworkEncryption

The reference to the remote virtual network's encryption

properties.resourceGuid

string

The resourceGuid property of the Virtual Network peering resource.

properties.useRemoteGateways

boolean

If remote gateways can be used on this virtual network. If the flag is set to true, and allowGatewayTransit on remote peering is also true, virtual network will use gateways of remote virtual network for transit. Only one peering can have this flag set to true. This flag cannot be set if virtual network already has a gateway.

type

string

Resource type.

VirtualNetworkPeeringLevel

The peering sync status of the virtual network peering.

Name Type Description
FullyInSync

string

LocalAndRemoteNotInSync

string

LocalNotInSync

string

RemoteNotInSync

string

VirtualNetworkPeeringState

The status of the virtual network peering.

Name Type Description
Connected

string

Disconnected

string

Initiated

string