Skip to content

Commit d80b32b

Browse files
fixed hub and spoke scripts
1 parent 5e9deb5 commit d80b32b

6 files changed

+52
-22
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
# Change log for AzureSite2SiteVPNLab
22

3+
## 1.4.1 - February 18, 2022
4+
5+
- Fixed VnetSpoke subnet address on 3B-1 and 2 scripts; was calling an array not a single subnet. Future developments will support multiple subnets
6+
- Fixed resource checks for peering and public IP; set silently continue for non existing resources error
7+
- Added ISE check; PowerShell ISE has issues with prompting for password during VyOS setup. Recommend running in PowerShell or VSCode. Thanks Ankit Oberoi
8+
- Fixed AddressPrefix for LNG; Converted addresses into an array.
9+
- Verbose output during Az module check; provides clarity of what script is doing.
10+
311
## 1.4.0 - January 17, 2022
412

5-
- Fixed vyos setup script output; was out putting blank file in step 2
13+
- Fixed VyOS setup script output; was out putting blank file in step 2
614
- Added synopsis to each script; provide steps taken and parameters
715
- Add OStype parameter to simple Azure VM script; allow Windows 10 or Windows Server deployment
816
- Added domain join capability for VM; domain controller must exist

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ _BETA_: **Step 4A-2. Build Hyper-V VM.ps1** <-- Sets up a VM in Hyper-V (not una
159159
- Some ISP's may not allow VPN traffic; no know work around for this
160160
- These scripts have not been tested with Azure Gov or other Azure community clouds
161161
- After Site 2 Site VPN is created; step that check for connectivity may show _unknown) or _not connected_; this may be due to Azure's graph api call not updating immediately. Recommend manual check
162+
- Go to Azure Portal --> Local Network Gateways --> Click on new gateway --> Connections
162163
- VyOS router will remove it trusted ssh host list on each reboot. This is by design and will require login for each script implementation; looking for alternate method to resolve this
164+
- There are known issues with the PowerShell ISE interface during VyOS configurations; Recommend running with Powershell console or VScode.
165+
163166
## References
164167

165168
- [Create a VPN Gateway and add a Site-to-Site connection using PowerShell](https://docs.microsoft.com/en-us/azure/vpn-gateway/vpn-gateway-create-site-to-site-rm-powershell)

Step 3B-1. Build Azure Advanced S2S - Region 1.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ If(-Not($vNetB = Get-AzVirtualNetwork -Name $AzureAdvConfigSiteA.VnetSpokeName -
181181
Write-Host ("Creating Azure spoke virtual network [{0}]..." -f $AzureAdvConfigSiteA.VnetSpokeName) -ForegroundColor White -NoNewline
182182
Try{
183183
$vNetB = New-AzVirtualNetwork -Name $AzureAdvConfigSiteA.VnetSpokeName -ResourceGroupName $AzureAdvConfigSiteA.ResourceGroupName `
184-
-Location $AzureAdvConfigSiteA.LocationName -AddressPrefix $AzureAdvConfigSiteA.VnetSpokeCIDRPrefix[0]
184+
-Location $AzureAdvConfigSiteA.LocationName -AddressPrefix $AzureAdvConfigSiteA.VnetSpokeCIDRPrefix
185185
#Create a subnet configuration for first VM subnet (vnet B)
186186
Add-AzVirtualNetworkSubnetConfig -Name $AzureAdvConfigSiteA.VnetSpokeSubnetName -VirtualNetwork $vNetB `
187-
-AddressPrefix $AzureAdvConfigSiteA.VnetSpokeSubnetAddressPrefix | Out-Null
187+
-AddressPrefix $AzureAdvConfigSiteA.VnetSpokeSubnetAddressPrefix[0] | Out-Null
188188
Write-Host "Done" -ForegroundColor Green
189189
}
190190
Catch{
@@ -203,8 +203,8 @@ Else{
203203

204204
#region 4. Build Peering between vnets
205205
#https://docs.microsoft.com/en-us/azure/virtual-network/virtual-network-peering-overview
206-
If( -Not(Get-AzVirtualNetworkPeering -Name $AzureAdvConfigSiteA.VnetPeerNameAB -ResourceGroupName $AzureAdvConfigSiteA.ResourceGroupName -VirtualNetwork $vNetA.Name) -or `
207-
-Not(Get-AzVirtualNetworkPeering -Name $AzureAdvConfigSiteA.VnetPeerNameBA -ResourceGroupName $AzureAdvConfigSiteA.ResourceGroupName -VirtualNetwork $vNetB.Name) )
206+
If( -Not(Get-AzVirtualNetworkPeering -Name $AzureAdvConfigSiteA.VnetPeerNameAB -ResourceGroupName $AzureAdvConfigSiteA.ResourceGroupName -VirtualNetwork $vNetA.Name -ErrorAction SilentlyContinue) -or `
207+
-Not(Get-AzVirtualNetworkPeering -Name $AzureAdvConfigSiteA.VnetPeerNameBA -ResourceGroupName $AzureAdvConfigSiteA.ResourceGroupName -VirtualNetwork $vNetB.Name -ErrorAction SilentlyContinue) )
208208
{
209209
Write-Host ("Creating peering between vnets [{0}] and [{1}]..." -f $AzureAdvConfigSiteA.VnetPeerNameAB,$AzureAdvConfigSiteA.VnetPeerNameBA) -ForegroundColor White -NoNewline
210210
Try{
@@ -229,7 +229,7 @@ $gwsubnet = Get-AzVirtualNetworkSubnetConfig -Name 'GatewaySubnet' -VirtualNetwo
229229

230230

231231
#region 5. Create a Public IP address
232-
If( $null -eq ($azpip = Get-AzPublicIpAddress -Name $AzureAdvConfigSiteA.PublicIpName -ResourceGroupName $AzureAdvConfigSiteA.ResourceGroupName).IpAddress )
232+
If( $null -eq ($azpip = Get-AzPublicIpAddress -Name $AzureAdvConfigSiteA.PublicIpName -ResourceGroupName $AzureAdvConfigSiteA.ResourceGroupName -ErrorAction SilentlyContinue).IpAddress )
233233
{
234234
Write-Host ("Creating Azure public IP [{0}]..." -f $AzureAdvConfigSiteA.PublicIPName) -ForegroundColor White -NoNewline
235235
Try{
@@ -314,7 +314,7 @@ If( -Not($Local = Get-AzLocalNetworkGateway -Name $AzureAdvConfigSiteA.LocalGate
314314
Write-host ("Building the local network gateway [{0}]..." -f $AzureAdvConfigSiteA.LocalGatewayName) -ForegroundColor White -NoNewline
315315
Try{
316316
New-AzLocalNetworkGateway -Name $AzureAdvConfigSiteA.LocalGatewayName -ResourceGroupName $AzureAdvConfigSiteA.ResourceGroupName `
317-
-Location $AzureAdvConfigSiteA.LocationName -GatewayIpAddress $HomePublicIP -AddressPrefix $VyOSConfig.LocalSubnetPrefix.keys @LNGBGPParams | Out-Null
317+
-Location $AzureAdvConfigSiteA.LocationName -GatewayIpAddress $HomePublicIP -AddressPrefix @($VyOSConfig.LocalSubnetPrefix.GetEnumerator().Name) @LNGBGPParams | Out-Null
318318
Write-Host "Done" -ForegroundColor Green
319319
}
320320
Catch{
@@ -653,7 +653,7 @@ If($RunManualSteps){
653653
Write-Host "Information needed to configure local router vpn:" -ForegroundColor Yellow
654654
Write-Host ("Azure Location: {0}" -f $AzureAdvConfigSiteA.LocationName)
655655
Write-Host ("Azure Peer Public IP: {0}" -f $azpip.IpAddress)
656-
Write-Host ("Remote Subnet Prefix: {0}" -f $AzureAdvConfigSiteA.VnetSpokeSubnetAddressPrefix)
656+
Write-Host ("Remote Subnet Prefix: {0}" -f ($AzureAdvConfigSiteA.VnetSpokeSubnetAddressPrefix -join ','))
657657
Write-host ("Shared Key (PSK): {0}" -f $Global:RegionASharedPSK)
658658
Write-Host ("BGP Enabled: {0}" -f $UseBGP.ToString())
659659
If($UseBGP){

Step 3B-2. Build Azure Advanced S2S - Region 2.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ If(-Not($vNetB = Get-AzVirtualNetwork -Name $AzureAdvConfigSiteB.VnetSpokeName -
128128
Write-Host ("Creating Azure spoke virtual network [{0}]..." -f $AzureAdvConfigSiteB.VnetSpokeName) -ForegroundColor White -NoNewline
129129
Try{
130130
$vNetB = New-AzVirtualNetwork -Name $AzureAdvConfigSiteB.VnetSpokeName -ResourceGroupName $AzureAdvConfigSiteB.ResourceGroupName `
131-
-Location $AzureAdvConfigSiteB.LocationName -AddressPrefix $AzureAdvConfigSiteB.VnetSpokeCIDRPrefix[0]
131+
-Location $AzureAdvConfigSiteB.LocationName -AddressPrefix $AzureAdvConfigSiteB.VnetSpokeCIDRPrefix
132132
#Create a subnet configuration for first VM subnet (vnet B)
133133
Add-AzVirtualNetworkSubnetConfig -Name $AzureAdvConfigSiteB.VnetSpokeSubnetName -VirtualNetwork $vNetB `
134-
-AddressPrefix $AzureAdvConfigSiteB.VnetSpokeSubnetAddressPrefix | Out-Null
134+
-AddressPrefix $AzureAdvConfigSiteB.VnetSpokeSubnetAddressPrefix[0] | Out-Null
135135
Write-Host "Done" -ForegroundColor Green
136136
}
137137
Catch{
@@ -150,8 +150,8 @@ Else{
150150

151151
#region 4. Build Peering between vnets
152152
#https://docs.microsoft.com/en-us/azure/virtual-network/virtual-network-peering-overview
153-
If( -Not(Get-AzVirtualNetworkPeering -Name $AzureAdvConfigSiteB.VnetPeerNameAB -ResourceGroupName $AzureAdvConfigSiteB.ResourceGroupName -VirtualNetwork $vNetA.Name) -or `
154-
-Not(Get-AzVirtualNetworkPeering -Name $AzureAdvConfigSiteB.VnetPeerNameBA -ResourceGroupName $AzureAdvConfigSiteB.ResourceGroupName -VirtualNetwork $vNetB.Name) )
153+
If( -Not(Get-AzVirtualNetworkPeering -Name $AzureAdvConfigSiteB.VnetPeerNameAB -ResourceGroupName $AzureAdvConfigSiteB.ResourceGroupName -VirtualNetwork $vNetA.Name -ErrorAction SilentlyContinue) -or `
154+
-Not(Get-AzVirtualNetworkPeering -Name $AzureAdvConfigSiteB.VnetPeerNameBA -ResourceGroupName $AzureAdvConfigSiteB.ResourceGroupName -VirtualNetwork $vNetB.Name -ErrorAction SilentlyContinue) )
155155
{
156156
Write-Host ("Creating peering between vnets [{0}] and [{1}]..." -f $AzureAdvConfigSiteB.VnetPeerNameAB,$AzureAdvConfigSiteB.VnetPeerNameBA) -ForegroundColor White -NoNewline
157157
Try{
@@ -176,7 +176,7 @@ $gwsubnet = Get-AzVirtualNetworkSubnetConfig -Name 'GatewaySubnet' -VirtualNetwo
176176

177177

178178
#region 5. Create a Public IP address
179-
If( $null -eq ($azpip = Get-AzPublicIpAddress -Name $AzureAdvConfigSiteB.PublicIpName -ResourceGroupName $AzureAdvConfigSiteB.ResourceGroupName).IpAddress )
179+
If( $null -eq ($azpip = Get-AzPublicIpAddress -Name $AzureAdvConfigSiteB.PublicIpName -ResourceGroupName $AzureAdvConfigSiteB.ResourceGroupName -ErrorAction SilentlyContinue).IpAddress )
180180
{
181181
Write-Host ("Creating Azure public IP [{0}]..." -f $AzureAdvConfigSiteB.PublicIPName) -ForegroundColor White -NoNewline
182182
Try{
@@ -261,7 +261,7 @@ If( -Not($Local = Get-AzLocalNetworkGateway -Name $AzureAdvConfigSiteB.LocalGate
261261
Write-host ("Building the local network gateway [{0}]..." -f $AzureAdvConfigSiteB.LocalGatewayName) -ForegroundColor White -NoNewline
262262
Try{
263263
New-AzLocalNetworkGateway -Name $AzureAdvConfigSiteB.LocalGatewayName -ResourceGroupName $AzureAdvConfigSiteB.ResourceGroupName `
264-
-Location $AzureAdvConfigSiteB.LocationName -GatewayIpAddress $HomePublicIP -AddressPrefix $VyOSConfig.LocalSubnetPrefix.keys @LNGBGPParams | Out-Null
264+
-Location $AzureAdvConfigSiteB.LocationName -GatewayIpAddress $HomePublicIP -AddressPrefix @($VyOSConfig.LocalSubnetPrefix.GetEnumerator().Name) @LNGBGPParams | Out-Null
265265
Write-Host "Done" -ForegroundColor Green
266266
}
267267
Catch{
@@ -273,7 +273,7 @@ ElseIf($Local.GatewayIpAddress -ne $HomePublicIP)
273273
{
274274
Try{
275275
Write-Host ("Updating the local network gateway with ip [{0}]" -f $HomePublicIP) -ForegroundColor Yellow -NoNewline
276-
#Update Local network gratway's connector IP address (onpremise IP)
276+
#Update Local network gateway's connector IP address (on-premise IP)
277277
New-AzLocalNetworkGateway -Name $AzureAdvConfigSiteB.LocalGatewayName -ResourceGroupName $AzureAdvConfigSiteB.ResourceGroupName `
278278
-Location $AzureAdvConfigSiteB.LocationName -GatewayIpAddress $HomePublicIP `
279279
-AddressPrefix @($VyOSConfig.LocalSubnetPrefix.GetEnumerator().Name) @LNGBGPParams -Force | Out-Null
@@ -333,7 +333,7 @@ Else{
333333
If( ($ReconfigureVpn -eq 'Y') -or ($VyOSConfig['ResetVPNConfigs'] -eq $true) )
334334
{
335335
Write-Host ("Attempting to update vyos router vpn configurations to use Azure's public IP [{0}]..." -f $azpip.IpAddress) -ForegroundColor Yellow
336-
$Global:RegionBSharedPSK = Get-AzVirtualNetworkGatewayConnectionSharedKey -Name $AzureAdvConfigSiteA.ConnectionName -ResourceGroupName $AzureAdvConfigSiteA.ResourceGroupName
336+
$Global:RegionBSharedPSK = Get-AzVirtualNetworkGatewayConnectionSharedKey -Name $AzureAdvConfigSiteB.ConnectionName -ResourceGroupName $AzureAdvConfigSiteB.ResourceGroupName
337337
$VyOSConfig['ResetVPNConfigs'] = $true
338338
}
339339
Else{
@@ -588,7 +588,7 @@ If($RunManualSteps){
588588
Write-Host "Information needed to configure local router vpn:" -ForegroundColor Yellow
589589
Write-Host ("Azure Location: {0}" -f $AzureAdvConfigSiteB.LocationName)
590590
Write-Host ("Azure Peer Public IP: {0}" -f $azpip.IpAddress)
591-
Write-Host ("Remote Subnet Prefix: {0}" -f $AzureAdvConfigSiteB.VnetSpokeSubnetAddressPrefix)
591+
Write-Host ("Remote Subnet Prefix: {0}" -f ($AzureAdvConfigSiteB.VnetSpokeSubnetAddressPrefix -Join ','))
592592
Write-host ("Shared Key (PSK): {0}" -f $Global:RegionBSharedPSK)
593593
Write-Host ("BGP Enabled: {0}" -f $UseBGP.ToString())
594594
If($UseBGP){

Step 4A-1. Build Azure VM.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ If($SecureVM){
339339
# Advisor Recommendation (high): Virtual machines should encrypt temp disks, caches, and data flows between Compute and Storage resources
340340
#https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disk-encryption-powershell-quickstart
341341
$KeyVaultName = ($LabPrefix + 'vmdiskkeys')
342-
If(-Not($AzKeyVault = AzKeyVault -Name $KeyVaultName -ResourceGroupName $AzureSimpleConfig.ResourceGroupName -Location eastus -ErrorAction SilentlyContinue -WarningAction SilentlyContinue)){
342+
If(-Not($AzKeyVault = AzKeyVault -Name $KeyVaultName -ResourceGroupName $AzureSimpleConfig.ResourceGroupName -ErrorAction SilentlyContinue -WarningAction SilentlyContinue)){
343343
Write-Host ("Creating Azure Keyvault [{0}]..." -f $KeyVaultName) -ForegroundColor White -NoNewline
344344
Try{
345345
$AzKeyVault = New-AzKeyVault -Name $KeyVaultName -ResourceGroupName $AzureSimpleConfig.ResourceGroupName -Location eastus -EnabledForDiskEncryption | Out-Null

configs.ps1

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
Param(
33
[switch]$NoAzureCheck,
44
[switch]$NoVyosISOCheck
5+
56
)
67
#============================================
78
# General Configurations - EDIT THIS
89
#============================================
10+
$IgnoreISECheck = $False #PowerShell ISE has issues with prompting for password during VYOS setup. Recommend running in PowerShell or VSCode.
911

1012
$LabPrefix = 'Contoso' #identifier for names in lab
1113

1214
$domain = 'contoso.com' #just a name for now (no DC install....yet)
1315

14-
$Email = '<email>' #used only in VM notification for VM autoshutdown settings
16+
$Email = '<email>' #used only in VM notification for VM auto shutdown settings
1517

1618
#this is used to configure default username and password on Azure VM's
1719
$VMAdminUser = 'xAdmin'
@@ -204,7 +206,7 @@ If($null -eq $scriptRoot){
204206
. "$FunctionPath\azure.ps1"
205207
#endregion
206208

207-
Write-Host "Processed functions. Loading configuration data..." -ForegroundColor Green
209+
Write-Host "Processed functions. Loading configuration data..." -ForegroundColor Cyan
208210

209211
#check if SSH and SCP exist for automation mode to work
210212
If(-Not(Test-Command ssh) -and -Not(Test-Command scp) -and -Not(Test-Command ssh-keygen) )
@@ -255,11 +257,14 @@ If(Test-SameSubnet -Ip1 ($AzureSiteBHubCIDR -replace '/\d+$','') -ip2 ($AzureSit
255257
#============================================
256258
#region connect to Azure if not already connected
257259
If(!$NoAzureCheck){
260+
Write-Host "Checking for Az Powershell module..." -ForegroundColor White -NoNewline
258261
If((Find-Module Az).Version -in (Get-InstalledModule Az -AllVersions).version){
259-
Write-Verbose "Az Module Loaded"
262+
Write-Host ("Az Module [{0}] installed" -f (Get-InstalledModule Az -AllVersions).version) -ForegroundColor Green
260263
}
261264
Else{
265+
Write-Host "Updating module, this can take awhile..." -ForegroundColor Yellow -NoNewline
262266
Install-Module -Name Az -AllowClobber -Scope AllUsers -Force
267+
Write-Host "Done" -ForegroundColor Green
263268
}
264269

265270
Try{
@@ -289,6 +294,20 @@ If(!$NoAzureCheck){
289294
}
290295
}
291296
#endregion
297+
298+
If(Test-IsISE){
299+
If($IgnoreISECheck -eq $False){
300+
Write-Host "===============================" -ForegroundColor Black -BackgroundColor Yellow
301+
Write-Host " CONTINUE AT OWN RISK " -ForegroundColor Black -BackgroundColor Yellow
302+
Write-Host "===============================" -ForegroundColor Black -BackgroundColor Yellow
303+
Write-Host "You are currently running this script using PowerShell ISE.`nThere are known issues with the interface during vyos configurations" -ForegroundColor Yellow
304+
$ISEResponse = Read-host "Would you like to continue? [Y or N]"
305+
If ($ISEResponse -eq 'N'){
306+
Break
307+
}
308+
}
309+
}
310+
292311
#============================================
293312
# HYPER-V CHECK
294313
#============================================
@@ -369,7 +388,7 @@ If(!$NoVyosISOCheck){
369388
Write-Host "Done" -ForegroundColor Green
370389
}
371390
Catch{
372-
Write-host ('UNable to download [{0}]: {1}' -f $vyosfilename,$_.Exception.message) -ForegroundColor Black -BackgroundColor Red
391+
Write-host ('Unable to download [{0}]: {1}' -f $vyosfilename,$_.Exception.message) -ForegroundColor Black -BackgroundColor Red
373392
break
374393
}
375394
Finally{

0 commit comments

Comments
 (0)