Skip to content

Commit e5fcd5c

Browse files
authored
Adding new optional parameter to specify dns servers for Virtual Wan P2SVpnGateway and P2SClients (#12006)
* Adding new optional parameter to specify dns servers for Virtual Wan-P2SVpnGateway and P2SClients * Incorporate code review comments and added test record * Suppress warnings * Suppress cred scan errors
1 parent 2b76cb9 commit e5fcd5c

File tree

13 files changed

+28121
-6846
lines changed

13 files changed

+28121
-6846
lines changed

src/Network/Network.Test/ScenarioTests/CortexTests.ps1

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ function Test-CortexExpressRouteCRUD
513513
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation
514514

515515
# Create the Virtual Wan
516-
$createdVirtualWan = New-AzVirtualWan -ResourceGroupName $rgName -Name $virtualWanName -Location $rglocation
516+
$createdVirtualWan = New-AzVirtualWan -ResourceGroupName $rgName -Name $virtualWanName -Location $rglocation -AllowVnetToVnetTraffic
517517
$virtualWan = Get-AzVirtualWan -ResourceGroupName $rgName -Name $virtualWanName
518518
Assert-AreEqual $rgName $virtualWan.ResourceGroupName
519519
Assert-AreEqual $virtualWanName $virtualWan.Name
@@ -548,7 +548,10 @@ function Test-CortexExpressRouteCRUD
548548
$vpnClientAddressSpaces = New-Object string[] 2
549549
$vpnClientAddressSpaces[0] = "192.168.2.0/24"
550550
$vpnClientAddressSpaces[1] = "192.168.3.0/24"
551-
$createdP2SVpnGateway = New-AzP2sVpnGateway -ResourceGroupName $rgName -Name $P2SvpnGatewayName -VirtualHub $virtualHub -VpnGatewayScaleUnit 1 -VpnClientAddressPool $vpnClientAddressSpaces -VpnServerConfiguration $vpnServerConfig1
551+
$customDnsServers = New-Object string[] 2
552+
$customDnsServers[0] = "7.7.7.7"
553+
$customDnsServers[1] = "8.8.8.8"
554+
$createdP2SVpnGateway = New-AzP2sVpnGateway -ResourceGroupName $rgName -Name $P2SvpnGatewayName -VirtualHub $virtualHub -VpnGatewayScaleUnit 1 -VpnClientAddressPool $vpnClientAddressSpaces -VpnServerConfiguration $vpnServerConfig1 -CustomDnsServer $customDnsServers
552555
Assert-AreEqual "Succeeded" $createdP2SVpnGateway.ProvisioningState
553556

554557
# Get the created P2SVpnGateway using Get-AzP2sVpnGateway
@@ -557,6 +560,9 @@ function Test-CortexExpressRouteCRUD
557560
Assert-AreEqual $P2SvpnGatewayName $P2SVpnGateway.Name
558561
Assert-AreEqual $vpnServerConfig1.Id $P2SVpnGateway.VpnServerConfiguration.Id
559562
Assert-AreEqual "Succeeded" $P2SVpnGateway.ProvisioningState
563+
Assert-AreEqual 2 @($P2SVpnGateway.CustomDnsServers).Count
564+
Assert-AreEqual "7.7.7.7" $P2SVpnGateway.CustomDnsServers[0]
565+
Assert-AreEqual "8.8.8.8" $P2SVpnGateway.CustomDnsServers[1]
560566

561567
# Get all associated VpnServerConfigurations at Wan level using Get-AzVirtualWanVpnServerConfiguration
562568
$associatedVpnServerConfigs = Get-AzVirtualWanVpnServerConfiguration -Name $virtualWanName -ResourceGroupName $rgName
@@ -612,17 +618,25 @@ function Test-CortexExpressRouteCRUD
612618
$VpnServerConfig2Get = Get-AzVpnServerConfiguration -ResourceGroupName $rgName -Name $VpnServerConfiguration2Name
613619
Assert-AreEqual "TestRadiusServer3" $VpnServerConfig2Get.RadiusServerAddress
614620

615-
# Update existing P2SVpnGateway with new VpnClientAddressPool using Update-AzP2sVpnGateway
621+
# Update existing P2SVpnGateway with new VpnClientAddressPool and CustomDnsServers using Update-AzP2sVpnGateway
616622
$vpnClientAddressSpaces[1] = "192.168.4.0/24"
617-
$updatedP2SVpnGateway = Update-AzP2sVpnGateway -ResourceGroupName $rgName -Name $P2SvpnGatewayName -VpnClientAddressPool $vpnClientAddressSpaces
623+
$updatedP2SVpnGateway = Update-AzP2sVpnGateway -ResourceGroupName $rgName -Name $P2SvpnGatewayName -VpnClientAddressPool $vpnClientAddressSpaces -CustomDnsServer 9.9.9.9
618624

619625
$P2SVpnGateway = Get-AzP2sVpnGateway -ResourceGroupName $rgName -Name $P2SvpnGatewayName
620626
Assert-AreEqual $P2SvpnGatewayName $P2SVpnGateway.Name
621627
Assert-AreEqual "Succeeded" $P2SVpnGateway.ProvisioningState
622628
Assert-AreEqual $vpnServerConfig1.Id $P2SVpnGateway.VpnServerConfiguration.Id
623629
$setVpnClientAddressSpacesString = [system.String]::Join(" ", $vpnClientAddressSpaces)
624630
Assert-AreEqual $setVpnClientAddressSpacesString $P2SVpnGateway.P2SConnectionConfigurations[0].VpnClientAddressPool.AddressPrefixes
625-
631+
Assert-AreEqual 1 @($P2SVpnGateway.CustomDnsServers).Count
632+
Assert-AreEqual "9.9.9.9" $P2SVpnGateway.CustomDnsServers[0]
633+
634+
# Update existing P2SVpnGateway to remove the CustomDnsServers
635+
$P2SVpnGateway = Get-AzP2sVpnGateway -ResourceGroupName $rgName -Name $P2SvpnGatewayName
636+
Update-AzP2sVpnGateway -ResourceGroupName $rgName -Name $P2SvpnGatewayName -CustomDnsServer @()
637+
$P2SVpnGateway = Get-AzP2sVpnGateway -ResourceGroupName $rgName -Name $P2SvpnGatewayName
638+
Assert-AreEqual 0 @($P2SVpnGateway.CustomDnsServers).Count
639+
626640
$associatedVpnServerConfigs = Get-AzVirtualWanVpnServerConfiguration -ResourceId $virtualWan.Id
627641
Assert-NotNull $associatedVpnServerConfigs
628642
Assert-AreEqual 1 @($associatedVpnServerConfigs.VpnServerConfigurationResourceIds).Count

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.CortexTests/TestP2SCortexCRUD.json

Lines changed: 27952 additions & 6775 deletions
Large diffs are not rendered by default.

src/Network/Network/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
* Add `EnableDnsProxy`, 'DnsProxyNotRequiredForNetworkRule' and 'DnsServer' parameters to `AzureFirewall`
5151
- Updated cmdlet:
5252
- New-AzFirewall
53+
* Updated below commands for feature: Custom dns servers set/remove on VirtualWan P2SVpnGateway.
54+
- 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.
55+
- 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.
5356

5457
## Version 2.5.0
5558
* Updated cmdlets to enable connection on private IP for Virtual Network Gateway.

src/Network/Network/Cortex/P2SVpnGateway/NewAzureRmP2sVpnGatewayCommand.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ public class NewAzureRmP2SVpnGatewayCommand : P2SVpnGatewayBaseCmdlet
131131
[ValidateNotNullOrEmpty]
132132
public string[] VpnClientAddressPool { get; set; }
133133

134+
[Parameter(
135+
Mandatory = false,
136+
ValueFromPipelineByPropertyName = true,
137+
HelpMessage = "The list of Custom Dns Servers.")]
138+
public string[] CustomDnsServer { get; set; }
139+
134140
[Parameter(
135141
Mandatory = false,
136142
HelpMessage = "A hashtable which represents resource tags.")]
@@ -227,6 +233,12 @@ public override void Execute()
227233
p2sVpnGateway.VpnServerConfiguration = new PSResourceId() { Id = vpnServerConfigurationResolvedId };
228234
p2sVpnGateway.VpnServerConfigurationLocation = string.IsNullOrWhiteSpace(this.VpnServerConfiguration.Location) ? string.Empty : this.VpnServerConfiguration.Location;
229235

236+
// Set the custom dns servers, if it is specified by customer.
237+
if (CustomDnsServer != null && this.CustomDnsServer.Any())
238+
{
239+
p2sVpnGateway.CustomDnsServers = CustomDnsServer?.ToList();
240+
}
241+
230242
ConfirmAction(
231243
Properties.Resources.CreatingResourceMessage,
232244
this.Name,

src/Network/Network/Cortex/P2SVpnGateway/UpdateAzureRmP2SVpnGatewayCommand.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ public class UpdateAzureRmP2SVpnGatewayCommand : P2SVpnGatewayBaseCmdlet
152152
HelpMessage = "The scale unit for this P2SVpnGateway.")]
153153
public uint VpnGatewayScaleUnit { get; set; }
154154

155+
[Parameter(
156+
Mandatory = false,
157+
ValueFromPipelineByPropertyName = true,
158+
HelpMessage = "The list of Custom Dns Servers.")]
159+
public string[] CustomDnsServer { get; set; }
160+
155161
[Parameter(
156162
Mandatory = false,
157163
HelpMessage = "A hashtable which represents resource tags.")]
@@ -219,6 +225,16 @@ public override void Execute()
219225
}
220226
}
221227

228+
// Set the custom dns servers, if it is specified by customer.
229+
if (CustomDnsServer != null && this.CustomDnsServer.Any())
230+
{
231+
existingP2SVpnGateway.CustomDnsServers = CustomDnsServer?.ToList();
232+
}
233+
else
234+
{
235+
existingP2SVpnGateway.CustomDnsServers = null;
236+
}
237+
222238
//// Resolve the VpnServerConfiguration, if specified
223239
string vpnServerConfigurationResourceGroupName = string.Empty;
224240
string vpnServerConfigurationName = string.Empty;

src/Network/Network/Cortex/VirtualWan/GetAzureRmVirtualWanVpnServerConfiguration.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ public class GetAzureRmVirtualWanVpnServerConfigurationsCommand : VirtualWanBase
3535
{
3636
[Alias("ResourceName")]
3737
[Parameter(
38-
Mandatory = false,
38+
ParameterSetName = CortexParameterSetNames.ByVirtualWanName,
39+
Mandatory = true,
3940
ValueFromPipelineByPropertyName = true,
4041
HelpMessage = "The resource name.")]
4142
[ResourceNameCompleter("Microsoft.Network/virtualWans", "ResourceGroupName")]
4243
[ValidateNotNullOrEmpty]
4344
public string Name { get; set; }
4445

4546
[Parameter(
47+
ParameterSetName = CortexParameterSetNames.ByVirtualWanName,
4648
Mandatory = true,
4749
ValueFromPipelineByPropertyName = true,
4850
HelpMessage = "The resource group name.")]

src/Network/Network/Models/Cortex/PSP2SVpnGateway.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public class PSP2SVpnGateway : PSTopLevelResource
3939
[Ps1Xml(Label = "Provisioning State", Target = ViewControl.Table)]
4040
public string ProvisioningState { get; set; }
4141

42+
public List<string> CustomDnsServers { get; set; }
43+
4244
[JsonIgnore]
4345
public string VpnClientConnectionHealthText
4446
{
@@ -50,5 +52,11 @@ public string P2SConnectionConfigurationsText
5052
{
5153
get { return JsonConvert.SerializeObject(P2SConnectionConfigurations, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
5254
}
55+
56+
[JsonIgnore]
57+
public string CustomDnsServersText
58+
{
59+
get { return JsonConvert.SerializeObject(CustomDnsServers, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
60+
}
5361
}
5462
}

src/Network/Network/Network.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<PsModuleName>Network</PsModuleName>

src/Network/Network/help/Get-AzVirtualWanVpnServerConfiguration.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ VpnServerConfigurationResourceIds : [
4949
The credentials, account, tenant, and subscription used for communication with Azure.
5050

5151
```yaml
52-
Type: IAzureContextContainer
52+
Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
5353
Parameter Sets: (All)
5454
Aliases: AzContext, AzureRmContext, AzureCredential
5555

@@ -64,8 +64,8 @@ Accept wildcard characters: False
6464
The resource name.
6565
6666
```yaml
67-
Type: String
68-
Parameter Sets: ByVirtualWanName
67+
Type: System.String
68+
Parameter Sets: (All)
6969
Aliases: ResourceName
7070

7171
Required: False
@@ -79,8 +79,8 @@ Accept wildcard characters: False
7979
The resource group name.
8080
8181
```yaml
82-
Type: String
83-
Parameter Sets: ByVirtualWanName
82+
Type: System.String
83+
Parameter Sets: (All)
8484
Aliases:
8585

8686
Required: True
@@ -94,7 +94,7 @@ Accept wildcard characters: False
9494
The Azure resource ID for the virtual wan.
9595
9696
```yaml
97-
Type: String
97+
Type: System.String
9898
Parameter Sets: ByVirtualWanResourceId
9999
Aliases: VirtualWanId
100100

@@ -109,7 +109,7 @@ Accept wildcard characters: False
109109
The virtual wan object.
110110
111111
```yaml
112-
Type: PSVirtualWan
112+
Type: Microsoft.Azure.Commands.Network.Models.PSVirtualWan
113113
Parameter Sets: ByVirtualWanObject
114114
Aliases: VirtualWan
115115

0 commit comments

Comments
 (0)