From 6c71be844c930e9b8c9bef1b9fba6dcc8505022c Mon Sep 17 00:00:00 2001 From: Nilambari Date: Wed, 6 May 2020 10:41:22 -0700 Subject: [PATCH] Adding new optional parameter to specify dns servers for Virtual Wan- P2SVpnGateway and P2SClients --- src/Network/Network.Test/Network.Test.csproj | 2 +- .../ScenarioTests/CortexTests.ps1 | 24 +++++++++++++++---- src/Network/Network/ChangeLog.md | 3 +++ .../NewAzureRmP2sVpnGatewayCommand.cs | 12 ++++++++++ .../UpdateAzureRmP2SVpnGatewayCommand.cs | 16 +++++++++++++ .../Network/Models/Cortex/PSP2SVpnGateway.cs | 8 +++++++ src/Network/Network/Network.csproj | 4 ++-- 7 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/Network/Network.Test/Network.Test.csproj b/src/Network/Network.Test/Network.Test.csproj index 8a023e1660d8..0d1658ba7268 100644 --- a/src/Network/Network.Test/Network.Test.csproj +++ b/src/Network/Network.Test/Network.Test.csproj @@ -14,7 +14,7 @@ - + diff --git a/src/Network/Network.Test/ScenarioTests/CortexTests.ps1 b/src/Network/Network.Test/ScenarioTests/CortexTests.ps1 index dfdb416c2a6c..13fe9668afd6 100644 --- a/src/Network/Network.Test/ScenarioTests/CortexTests.ps1 +++ b/src/Network/Network.Test/ScenarioTests/CortexTests.ps1 @@ -513,7 +513,7 @@ function Test-CortexExpressRouteCRUD $resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation # Create the Virtual Wan - $createdVirtualWan = New-AzVirtualWan -ResourceGroupName $rgName -Name $virtualWanName -Location $rglocation + $createdVirtualWan = New-AzVirtualWan -ResourceGroupName $rgName -Name $virtualWanName -Location $rglocation -AllowVnetToVnetTraffic $virtualWan = Get-AzVirtualWan -ResourceGroupName $rgName -Name $virtualWanName Assert-AreEqual $rgName $virtualWan.ResourceGroupName Assert-AreEqual $virtualWanName $virtualWan.Name @@ -548,7 +548,10 @@ function Test-CortexExpressRouteCRUD $vpnClientAddressSpaces = New-Object string[] 2 $vpnClientAddressSpaces[0] = "192.168.2.0/24" $vpnClientAddressSpaces[1] = "192.168.3.0/24" - $createdP2SVpnGateway = New-AzP2sVpnGateway -ResourceGroupName $rgName -Name $P2SvpnGatewayName -VirtualHub $virtualHub -VpnGatewayScaleUnit 1 -VpnClientAddressPool $vpnClientAddressSpaces -VpnServerConfiguration $vpnServerConfig1 + $customDnsServers = New-Object string[] 2 + $customDnsServers[0] = "7.7.7.7" + $customDnsServers[1] = "8.8.8.8" + $createdP2SVpnGateway = New-AzP2sVpnGateway -ResourceGroupName $rgName -Name $P2SvpnGatewayName -VirtualHub $virtualHub -VpnGatewayScaleUnit 1 -VpnClientAddressPool $vpnClientAddressSpaces -VpnServerConfiguration $vpnServerConfig1 -CustomDnsServer $customDnsServers Assert-AreEqual "Succeeded" $createdP2SVpnGateway.ProvisioningState # Get the created P2SVpnGateway using Get-AzP2sVpnGateway @@ -557,6 +560,9 @@ function Test-CortexExpressRouteCRUD Assert-AreEqual $P2SvpnGatewayName $P2SVpnGateway.Name Assert-AreEqual $vpnServerConfig1.Id $P2SVpnGateway.VpnServerConfiguration.Id Assert-AreEqual "Succeeded" $P2SVpnGateway.ProvisioningState + Assert-AreEqual 2 @($P2SVpnGateway.CustomDnsServers).Count + Assert-AreEqual "7.7.7.7" $P2SVpnGateway.CustomDnsServers[0] + Assert-AreEqual "8.8.8.8" $P2SVpnGateway.CustomDnsServers[1] # Get all associated VpnServerConfigurations at Wan level using Get-AzVirtualWanVpnServerConfiguration $associatedVpnServerConfigs = Get-AzVirtualWanVpnServerConfiguration -Name $virtualWanName -ResourceGroupName $rgName @@ -612,9 +618,9 @@ function Test-CortexExpressRouteCRUD $VpnServerConfig2Get = Get-AzVpnServerConfiguration -ResourceGroupName $rgName -Name $VpnServerConfiguration2Name Assert-AreEqual "TestRadiusServer3" $VpnServerConfig2Get.RadiusServerAddress - # Update existing P2SVpnGateway with new VpnClientAddressPool using Update-AzP2sVpnGateway + # Update existing P2SVpnGateway with new VpnClientAddressPool and CustomDnsServers using Update-AzP2sVpnGateway $vpnClientAddressSpaces[1] = "192.168.4.0/24" - $updatedP2SVpnGateway = Update-AzP2sVpnGateway -ResourceGroupName $rgName -Name $P2SvpnGatewayName -VpnClientAddressPool $vpnClientAddressSpaces + $updatedP2SVpnGateway = Update-AzP2sVpnGateway -ResourceGroupName $rgName -Name $P2SvpnGatewayName -VpnClientAddressPool $vpnClientAddressSpaces -CustomDnsServer 9.9.9.9 $P2SVpnGateway = Get-AzP2sVpnGateway -ResourceGroupName $rgName -Name $P2SvpnGatewayName Assert-AreEqual $P2SvpnGatewayName $P2SVpnGateway.Name @@ -622,7 +628,15 @@ function Test-CortexExpressRouteCRUD Assert-AreEqual $vpnServerConfig1.Id $P2SVpnGateway.VpnServerConfiguration.Id $setVpnClientAddressSpacesString = [system.String]::Join(" ", $vpnClientAddressSpaces) Assert-AreEqual $setVpnClientAddressSpacesString $P2SVpnGateway.P2SConnectionConfigurations[0].VpnClientAddressPool.AddressPrefixes - + Assert-AreEqual 1 @($P2SVpnGateway.CustomDnsServers).Count + Assert-AreEqual "9.9.9.9" $P2SVpnGateway.CustomDnsServers[0] + + # Update existing P2SVpnGateway to remove the CustomDnsServers + $P2SVpnGateway = Get-AzP2sVpnGateway -ResourceGroupName $rgName -Name $P2SvpnGatewayName + Update-AzP2sVpnGateway -ResourceGroupName $rgName -Name $P2SvpnGatewayName -CustomDnsServer @() + $P2SVpnGateway = Get-AzP2sVpnGateway -ResourceGroupName $rgName -Name $P2SvpnGatewayName + Assert-AreEqual 0 @($P2SVpnGateway.CustomDnsServers).Count + $associatedVpnServerConfigs = Get-AzVirtualWanVpnServerConfiguration -ResourceId $virtualWan.Id Assert-NotNull $associatedVpnServerConfigs Assert-AreEqual 1 @($associatedVpnServerConfigs.VpnServerConfigurationResourceIds).Count diff --git a/src/Network/Network/ChangeLog.md b/src/Network/Network/ChangeLog.md index 02c649d49d8c..c404dff15c51 100644 --- a/src/Network/Network/ChangeLog.md +++ b/src/Network/Network/ChangeLog.md @@ -20,6 +20,9 @@ ## Upcoming Release * Fixed incorrect type of SuccessThresholdRoundTripTimeMs parameter for New-AzNetworkWatcherConnectionMonitorTestConfigurationObject +* Updated below commands for feature: Custom dns servers set/remove on VirtualWan P2SVpnGateway. + - Updated New-AzP2sVpnGateway: Added optional parameter -CustomDnsServer for customers to specify their dns servers to set on P2SVpnGateway, which can be used by Point to site clients. + - Updated Update-AzP2sVpnGateway: Added optional parameter -CustomDnsServer for customers to specify their dns servers to set on P2SVpnGateway, which can be used by Point to site clients. ## Version 2.5.0 * Updated cmdlets to enable connection on private IP for Virtual Network Gateway. diff --git a/src/Network/Network/Cortex/P2SVpnGateway/NewAzureRmP2sVpnGatewayCommand.cs b/src/Network/Network/Cortex/P2SVpnGateway/NewAzureRmP2sVpnGatewayCommand.cs index c4d6502c77b8..1ccb908baf37 100644 --- a/src/Network/Network/Cortex/P2SVpnGateway/NewAzureRmP2sVpnGatewayCommand.cs +++ b/src/Network/Network/Cortex/P2SVpnGateway/NewAzureRmP2sVpnGatewayCommand.cs @@ -131,6 +131,12 @@ public class NewAzureRmP2SVpnGatewayCommand : P2SVpnGatewayBaseCmdlet [ValidateNotNullOrEmpty] public string[] VpnClientAddressPool { get; set; } + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The list of Custom Dns Servers.")] + public string[] CustomDnsServer { get; set; } + [Parameter( Mandatory = false, HelpMessage = "A hashtable which represents resource tags.")] @@ -227,6 +233,12 @@ public override void Execute() p2sVpnGateway.VpnServerConfiguration = new PSResourceId() { Id = vpnServerConfigurationResolvedId }; p2sVpnGateway.VpnServerConfigurationLocation = string.IsNullOrWhiteSpace(this.VpnServerConfiguration.Location) ? string.Empty : this.VpnServerConfiguration.Location; + // Set the custom dns servers, if it is specified by customer. + if (CustomDnsServer != null && this.CustomDnsServer.Any()) + { + p2sVpnGateway.CustomDnsServers = CustomDnsServer?.ToList(); + } + ConfirmAction( Properties.Resources.CreatingResourceMessage, this.Name, diff --git a/src/Network/Network/Cortex/P2SVpnGateway/UpdateAzureRmP2SVpnGatewayCommand.cs b/src/Network/Network/Cortex/P2SVpnGateway/UpdateAzureRmP2SVpnGatewayCommand.cs index ff69a7cdd70e..b303dd31bbd8 100644 --- a/src/Network/Network/Cortex/P2SVpnGateway/UpdateAzureRmP2SVpnGatewayCommand.cs +++ b/src/Network/Network/Cortex/P2SVpnGateway/UpdateAzureRmP2SVpnGatewayCommand.cs @@ -152,6 +152,12 @@ public class UpdateAzureRmP2SVpnGatewayCommand : P2SVpnGatewayBaseCmdlet HelpMessage = "The scale unit for this P2SVpnGateway.")] public uint VpnGatewayScaleUnit { get; set; } + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "The list of Custom Dns Servers.")] + public string[] CustomDnsServer { get; set; } + [Parameter( Mandatory = false, HelpMessage = "A hashtable which represents resource tags.")] @@ -219,6 +225,16 @@ public override void Execute() } } + // Set the custom dns servers, if it is specified by customer. + if (CustomDnsServer != null && this.CustomDnsServer.Any()) + { + existingP2SVpnGateway.CustomDnsServers = CustomDnsServer?.ToList(); + } + else + { + existingP2SVpnGateway.CustomDnsServers = null; + } + //// Resolve the VpnServerConfiguration, if specified string vpnServerConfigurationResourceGroupName = string.Empty; string vpnServerConfigurationName = string.Empty; diff --git a/src/Network/Network/Models/Cortex/PSP2SVpnGateway.cs b/src/Network/Network/Models/Cortex/PSP2SVpnGateway.cs index d1202284caca..311ffccb2153 100644 --- a/src/Network/Network/Models/Cortex/PSP2SVpnGateway.cs +++ b/src/Network/Network/Models/Cortex/PSP2SVpnGateway.cs @@ -39,6 +39,8 @@ public class PSP2SVpnGateway : PSTopLevelResource [Ps1Xml(Label = "Provisioning State", Target = ViewControl.Table)] public string ProvisioningState { get; set; } + public List CustomDnsServers { get; set; } + [JsonIgnore] public string VpnClientConnectionHealthText { @@ -50,5 +52,11 @@ public string P2SConnectionConfigurationsText { get { return JsonConvert.SerializeObject(P2SConnectionConfigurations, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); } } + + [JsonIgnore] + public string CustomDnsServersText + { + get { return JsonConvert.SerializeObject(CustomDnsServers, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); } + } } } \ No newline at end of file diff --git a/src/Network/Network/Network.csproj b/src/Network/Network/Network.csproj index 2131c0b0aec8..7de2ab7c4cf1 100644 --- a/src/Network/Network/Network.csproj +++ b/src/Network/Network/Network.csproj @@ -1,4 +1,4 @@ - + Network @@ -14,7 +14,7 @@ - +