# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .ps1
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: .NET (PowerShell)
#     language: PowerShell
#     name: .net-powershell
# ---

# # Virtual WAN Lab Environment 

# ### Variables used in this Lab Environment.
# **Change envprefix and vmprefix**

# +
$envprefix = 'ntvwan26'
$vmprefix = 'nt2'
$rgName = 'rg'+$envprefix
$vm1Name = $vmprefix+'vm1'
$nsg1name = $vmprefix+'-nsg1'
$pip1name =$vmprefix+'-pip1'
$vm2Name = $vmprefix+'vm2'
$nsg2name = $vmprefix+'-nsg2'
$pip2name =$vmprefix+'-pip2'
$rglocation = 'australiaeast'
$virtualWanName = $envprefix+'-vwan'
$virtualHub1Name = $envprefix+'Hub1'
$virtualHub2Name = $envprefix+'Hub2'
$virtualhub1addprefix = '10.60.0.0/24'
$virtualhub2addprefix = '10.70.0.0/24'
$virtualhub2location = 'southeastasia'
$remoteVirtualNetwork1Name = $envprefix+'vnet1'
$remoteVirtualNetwork1addprefix = '10.61.0.0/24'
$remoteVirtualNetwork2Name = $envprefix+'vnet2'
$remoteVirtualNetwork2addprefix = '10.71.0.0/24'
$hubVnetConnection1Name = 'Hub1Connection'
$hubVnetConnection2Name = 'Hub2Connection'
$vpnGateway1Name = $envprefix+'vpn1'
$vpnGateway2Name = $envprefix+'vpn2'
$vpnSiteName = $envprefix+'-vpnsite'
$vpnSiteLink1Name = $envprefix+'-link1'
$vpnSiteLink2Name = $envprefix+'-link2'
$vpnSiteAddressSpaces = New-Object string[] 1
$vpnSiteAddressSpaces[0] = "192.168.2.0/24"
$vpnSite2AddressSpaces = New-Object string[] 2
$vpnSite2AddressSpaces[0] = "172.16.17.32/24"
$vpnSite2AddressSpaces[1] = "172.16.31.10/24"
$vpnConnectionName = $envprefix+'-con1'
$VMLocalAdminUser = (Get-AzKeyVaultSecret -vaultName "USAZE-MSFTINT-PRD-KVLT01" -name "username").SecretValueText
$VMLocalAdminSecurePassword = ConvertTo-SecureString (Get-AzKeyVaultSecret -vaultName "USAZE-MSFTINT-PRD-KVLT01" `
                                 -name "password").SecretValueText -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($VMLocalAdminUser, $VMLocalAdminSecurePassword)


# -

# ### Create a resource group

$resourceGroup = New-AzResourceGroup -Name $rgName -Location $rglocation

# ### Create Two VNETs. One in Sydney and One in Singapore
#

# +
$remoteVirtualNetworksubnet1 = New-AzVirtualNetworkSubnetConfig `
    -Name 'Apps' `
    -AddressPrefix $remoteVirtualNetwork1addprefix

$remoteVirtualNetwork1 = New-AzVirtualNetwork `
    -ResourceGroupName $rgName `
    -Name $remoteVirtualNetwork1Name `
    -Location $rglocation `
    -AddressPrefix $remoteVirtualNetwork1addprefix `
    -Subnet $remoteVirtualNetworksubnet1

$remoteVirtualNetworksubnet2 = New-AzVirtualNetworkSubnetConfig `
    -Name 'Apps' `
    -AddressPrefix $remoteVirtualNetwork2addprefix

$remoteVirtualNetwork2 = New-AzVirtualNetwork `
    -ResourceGroupName $rgName `
    -Name $remoteVirtualNetwork2Name `
    -Location $virtualhub2location `
    -AddressPrefix $remoteVirtualNetwork2addprefix `
    -Subnet $remoteVirtualNetworksubnet2
# -

# ### Create Virtual WAN Hubs, one in Singapore and one in Sydney

$createdVirtualWan = New-AzVirtualWan -ResourceGroupName $rgName `
    -Name $virtualWanName `
    -Location $rglocation `
    -AllowVnetToVnetTraffic `
    -AllowBranchToBranchTraffic


$virtualWan = Get-AzVirtualWan `
    -ResourceGroupName $rgName `
    -Name $virtualWanName

# ### Create Virtual WAN Hub in Sydney 

$createdVirtualHub = New-AzVirtualHub `
    -ResourceGroupName $rgName `
    -Name $virtualHub1Name `
    -Location $rglocation `
    -AddressPrefix $virtualhub1addprefix `
    -VirtualWan $virtualWan -AsJob


# ### Create Virtual WAN Hub in Singapore

$createdVirtualHub = New-AzVirtualHub `
    -ResourceGroupName $rgName `
    -Name $virtualHub2Name `
    -Location $virtualhub2location `
    -AddressPrefix $virtualhub2addprefix `
    -VirtualWan $virtualWan -AsJob

# ### Create VM in Sydney 

New-AzVm `
    -ResourceGroupName $rgName `
    -Name $vm1Name `
    -Location $rglocation `
    -VirtualNetworkName $remoteVirtualNetwork1Name `
    -SubnetName "Apps" `
    -SecurityGroupName $nsg1name `
    -PublicIpAddressName $pip1name `
    -Size "Standard_B2ms" `
    -Image "UbuntuLTS" `
    -OpenPorts 22 `
    -Credential $Credential `
    -AsJob

# ### Create VM in Singapore

New-AzVm `
    -ResourceGroupName $rgName `
    -Name $vm2Name `
    -Location $virtualhub2location `
    -VirtualNetworkName $remoteVirtualNetwork2Name `
    -SubnetName "Apps" `
    -SecurityGroupName $nsg2name `
    -PublicIpAddressName $pip2name `
    -Size "Standard_B2ms" `
    -Image "UbuntuLTS" `
    -OpenPorts 22 `
    -Credential $Credential `
    -AsJob


# ### Create VNET Connection with Virtual WAN Hub 

$createdHubVnetConnection1 = New-AzVirtualHubVnetConnection `
    -ResourceGroupName $rgName `
    -VirtualHubName $virtualHub1Name `
    -Name $hubVnetConnection1Name `
    -RemoteVirtualNetwork $remoteVirtualNetwork1 `
    -AsJob

# ### Create VNET Connection with Virtual WAN Hub 

$createdHubVnetConnection2 = New-AzVirtualHubVnetConnection `
    -ResourceGroupName $rgName `
    -VirtualHubName $virtualHub2Name `
    -Name $hubVnetConnection2Name `
    -RemoteVirtualNetwork $remoteVirtualNetwork2 `
    -AsJob

# ### Create Gateways for Sydney Virtual WAN Hub

$virtualHub1 = Get-AzVirtualHub -ResourceGroupName $rgName -Name $virtualHub1Name

$createdVpnGateway1 = New-AzVpnGateway `
    -ResourceGroupName $rgName `
    -Name $vpnGateway1Name `
    -VirtualHub $virtualHub1 `
    -VpnGatewayScaleUnit 1 `
    -AsJob

# ### Create Gateways for Singapore Virtual WAN Hub

$virtualHub2 = Get-AzVirtualHub -ResourceGroupName $rgName -Name $virtualHub2Name

$createdVpnGateway2 = New-AzVpnGateway `
    -ResourceGroupName $rgName `
    -Name $vpnGateway2Name `
    -VirtualHub $virtualHub2 `
    -VpnGatewayScaleUnit 1 `
    -AsJob

# ### Create VPN 

$createdVpnSite = New-AzVpnSite `
    -ResourceGroupName $rgName `
    -Name $vpnSiteName `
    -Location $rglocation `
    -VirtualWan $virtualWan `
    -IpAddress "172.16.17.32" `
    -AddressSpace $vpnSiteAddressSpaces `
    -DeviceModel "SomeDevice" `
    -DeviceVendor "SomeDeviceVendor" `
    -LinkSpeedInMbps 10
    -AsJob

# ### Create VPN Site

$createdVpnSite = New-AzVpnSite `
    -ResourceGroupName $rgName `
    -Name $vpnSiteName `
    -Location $rglocation `
    -VirtualWan $virtualWan `
    -IpAddress "172.16.17.32" `
    -AddressSpace $vpnSiteAddressSpaces `
    -DeviceModel "SomeDevice" `
    -DeviceVendor "SomeDeviceVendor" `
    -LinkSpeedInMbps 10
    -AsJob

# ### Create VPN Connection

$createdVpnConnection = New-AzVpnConnection `
    -ResourceGroupName $rgName `
    -ParentResourceName $vpnGateway1Name `
    -Name $vpnConnectionName `
    -VpnSite $vpnSite `
    -ConnectionBandwidth 20 `
    -UseLocalAzureIpAddress 
    -AsJob

# ### Cleanup

Remove-AzResourceGroup -Name $rgname -force -asjob





StarcoderdataJupyterScriptsDedupFiltered