This commit is contained in:
Alex Gonzalez 2021-12-02 23:40:10 +11:00
Родитель 962ac1fa7b
Коммит 97bfc889b1
6 изменённых файлов: 175 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,35 @@
# Sample
## Getting started
This sample uses [Bicep](https://docs.microsoft.com/en-us/azure/azure-resource-manager/bicep/overview) to deploy a cross region and cross subscription vnet peering.
### Install
1. Install the Azure CLI by following the [docs](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli) article.
1. Install Bicep from within the Azure CLI:
```
az bicep install
az bicep upgrade
```
### Login
1. Login and select your subscription
```
az login
```
### Deploy
1. Run the `deploy.ps1` script from the `src` directory of this sample:
```
cd deploy_crossSubPeer/src/
./deploy.ps1 -Subscription1 <your_first_subscription> -Subscription2 <your_second_subscription>
```

Просмотреть файл

@ -0,0 +1,29 @@
[CmdletBinding()]
param (
[Parameter(Mandatory=$true, Position=0)]
[string]
$Subscription1,
[Parameter(Mandatory=$true, Position=1)]
[string]
$Subscription2
)
$aue = 'australiaeast'
$ase = 'australiasoutheast'
Write-Output "deploying first vnet"
$aueVnetDep = az deployment sub create --subscription $Subscription1 --location $aue --template-file vnet/main.bicep --name xregionvnet-aue
$aueVnetId = ($aueVnetDep | ConvertFrom-Json).properties.outputs.vnetId.value; $aueVnetId
Write-Output "deploying second vnet"
$aseVnetDep = az deployment sub create --subscription $Subscription2 --location $ase --template-file vnet/main.bicep --name xregionvnet-ase
$aseVnetId = ($aseVnetDep | ConvertFrom-Json).properties.outputs.vnetId.value; $aseVnetId
Write-Output "peering first vnet to second vent"
$auePeerDep = az deployment sub create --subscription $Subscription1 --location $aue --template-file peer/main.bicep --name xregionpeer-aue --parameters vnetId=$aueVnetId remoteVnetId=$aseVnetId
$auePeerId = ($auePeerDep | ConvertFrom-Json).properties.outputs.peerId.value; $auePeerId
Write-Output "peering second vnet to first vent"
$asePeerDep = az deployment sub create --subscription $Subscription2 --location $ase --template-file peer/main.bicep --name xregionpeer-ase --parameters vnetId=$aseVnetId remoteVnetId=$aueVnetId
$asePeerId = ($asePeerDep | ConvertFrom-Json).properties.outputs.peerId.value; $asePeerId

Просмотреть файл

@ -0,0 +1,28 @@
targetScope = 'subscription'
param vnetId string
param remoteVnetId string
var location = deployment().location
var regionCodeLookup = {
australiaeast: 'aue'
australiasoutheast: 'ase'
}
var shortLocation = regionCodeLookup[location]
resource rg_xRegionPeer 'Microsoft.Resources/resourceGroups@2021-04-01' = {
location: location
name: '${shortLocation}-xRegionPeer'
}
module dep_peer 'peer.bicep' = {
name: '${shortLocation}-vnet'
scope: rg_xRegionPeer
params: {
vnetId: vnetId
remoteVnetId: remoteVnetId
}
}
output peerId string = dep_peer.outputs.peerId

Просмотреть файл

@ -0,0 +1,23 @@
param vnetId string
param remoteVnetId string
var vnetName = last(split(vnetId, '/'))
var remoteVnetName = last(split(remoteVnetId, '/'))
resource vnet 'Microsoft.Network/virtualNetworks@2021-03-01' existing = {
name: vnetName
}
resource peer 'Microsoft.Network/virtualNetworks/virtualNetworkPeerings@2021-03-01' = {
name: '${vnetName}-TO-${remoteVnetName}'
parent: vnet
properties: {
remoteVirtualNetwork: {
id: remoteVnetId
}
allowForwardedTraffic: true
allowVirtualNetworkAccess: true
}
}
output peerId string = peer.id

Просмотреть файл

@ -0,0 +1,32 @@
targetScope = 'subscription'
var location = deployment().location
var regionCodeLookup = {
australiaeast: 'aue'
australiasoutheast: 'ase'
}
var shortLocation = regionCodeLookup[location]
var regionPrefixLookup = {
australiaeast: '10.101.0.0/16'
australiasoutheast: '10.102.0.0/16'
}
var regionAddressPrefix = regionPrefixLookup[location]
resource rg_xRegionPeer 'Microsoft.Resources/resourceGroups@2021-04-01' = {
location: location
name: '${shortLocation}-xRegionPeer'
}
module dep_vnet 'vnet.bicep' = {
name: '${shortLocation}-vnet'
scope: rg_xRegionPeer
params: {
location: location
shortLocation: shortLocation
regionAddressPrefix: regionAddressPrefix
}
}
output vnetId string = dep_vnet.outputs.vnetId

Просмотреть файл

@ -0,0 +1,28 @@
param location string
param shortLocation string
param regionAddressPrefix string
var octet1 = int(split(regionAddressPrefix, '.')[0])
var octet2 = int(split(regionAddressPrefix, '.')[1])
resource net_vnet 'Microsoft.Network/virtualNetworks@2021-03-01' = {
name: '${shortLocation}-vnet'
location: location
properties: {
addressSpace: {
addressPrefixes: [
regionAddressPrefix
]
}
subnets: [
{
name: 'VmSubnet'
properties: {
addressPrefix: '${octet1}.${octet2}.0.0/28'
}
}
]
}
}
output vnetId string = net_vnet.id