Jul 16 2021 12:44 AM
Hi all,
I'm currently trying to create an AVD environment with nearly all required infrastructure via PowerShell: VNETs, Host Pools, etc. Right now I'm stuck at the creation step of the VPN Gateway. Feel free to take a look:
## Networking
# SubNets
$subnetDEVconfig = @{
Name = 'DevSubnet'
AddressPrefix = '10.0.1.0/24'
}
$subnetPRODconfig = @{
Name = 'ProdSubnet'
AddressPrefix = '10.0.2.0/24'
}
$subnetGatewayconfig = @{
Name = 'GatewaySubnet'
AddressPrefix = '10.0.0.0/27'
}
# VNET
$vnetconfig = @{
Name = 'VNET-AVD'
ResourceGroupName = $RGWVDEnv
Location = $locationGen
AddressPrefix = '10.0.0.0/20'
Subnet = $subnetDEVconfig,$subnetPRODconfig,$subnetGatewayconfig
}
Write-Host -ForegroundColor Green "Creating VNET"$vnetconfig.Name"with subnets"$subnetDEVconfig.Name","$subnetPRODconfig.Name"and"$subnetGatewayconfig.Name
$virtualNetwork = New-AzVirtualNetwork @vnetconfig
$virtualNetwork = Get-AzVirtualNetwork -Name $vnetconfig.Name -ResourceGroupName $RGWVDENV
## VPN
# Public IP
Write-Host -ForegroundColor Green "Creating VPN Gateway"
$gwpipconfig = @{
Name = 'Gateway-PIP-001'
ResourceGroupName = $RGGeneral
location = $locationGen
AllocationMethod = 'static'
}
New-AzPublicIpAddress @gwpipconfig
$gwvnet = Get-AzVirtualNetwork -Name $vnetconfig.Name -ResourceGroupName $RGWVDEnv
$gwsubnet = Get-AzVirtualNetworkSubnetConfig -Name $subnetGatewayconfig.Name -VirtualNetwork $gwvnet
$gwpipassign = New-AzVirtualNetworkGatewayIpConfig -Name 'GW-PIP-Config-001' -SubnetId $gwvnet.subnets[2].Id -PublicIpAddressId $gwpipconfig.Id
# Gateway
$gwconfig = @{
Name = 'AVD-VPN-Gateway-001'
ResourceGroupName = $RGGeneral
Location = $locationGen
IpConfigurations = $gwpipassign
GatewayType = 'VPN'
VpnType = 'RouteBased'
GatewaySku = 'Basic'
}
New-AzVirtualNetworkGateway @gwconfig
Running this results in the following error message I can't explain:
New-AzVirtualNetworkGateway: Public IP address reference is required for gateway IP configration /subscriptions/<<SUB-ID>>/resourceGroups/AVD-General-Services/providers/Microsoft.Network/virtualNetworkGateways/AVD-VPN-Gateway-001.
StatusCode: 400
ReasonPhrase: Bad Request
ErrorCode: PublicIpForGatewayIsRequired
ErrorMessage: Public IP address reference is required for gateway IP configration /subscriptions/<<SUB-ID>>/resourceGroups/AVD-General-Services/providers/Microsoft.Network/virtualNetworkGateways/AVD-VPN-Gateway-001.
OperationID : 710f7274-8875-4efe-9bfc-a940f0eda4a6
Does anyone can give me a hint, what I may have missed? As a source for the above snippet, I also used this: https://docs.microsoft.com/en-us/powershell/module/az.network/new-azvirtualnetworkgateway?view=azps-...
Jul 16 2021 02:56 AM
Jul 16 2021 04:25 AM
Solution