Skip to content

Adding new optional parameter to specify dns servers for Virtual Wan P2SVpnGateway and P2SClients #12006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/Network/Network.Test/ScenarioTests/CortexTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -612,17 +618,25 @@ 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
Assert-AreEqual "Succeeded" $P2SVpnGateway.ProvisioningState
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
Expand Down

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/Network/Network/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
* Add `EnableDnsProxy`, 'DnsProxyNotRequiredForNetworkRule' and 'DnsServer' parameters to `AzureFirewall`
- Updated cmdlet:
- New-AzFirewall
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.")]
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.")]
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ public class GetAzureRmVirtualWanVpnServerConfigurationsCommand : VirtualWanBase
{
[Alias("ResourceName")]
[Parameter(
Mandatory = false,
ParameterSetName = CortexParameterSetNames.ByVirtualWanName,
Mandatory = true,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource name.")]
[ResourceNameCompleter("Microsoft.Network/virtualWans", "ResourceGroupName")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(
ParameterSetName = CortexParameterSetNames.ByVirtualWanName,
Mandatory = true,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource group name.")]
Expand Down
8 changes: 8 additions & 0 deletions src/Network/Network/Models/Cortex/PSP2SVpnGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class PSP2SVpnGateway : PSTopLevelResource
[Ps1Xml(Label = "Provisioning State", Target = ViewControl.Table)]
public string ProvisioningState { get; set; }

public List<string> CustomDnsServers { get; set; }

[JsonIgnore]
public string VpnClientConnectionHealthText
{
Expand All @@ -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 }); }
}
}
}
2 changes: 1 addition & 1 deletion src/Network/Network/Network.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PsModuleName>Network</PsModuleName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ VpnServerConfigurationResourceIds : [
The credentials, account, tenant, and subscription used for communication with Azure.

```yaml
Type: IAzureContextContainer
Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
Parameter Sets: (All)
Aliases: AzContext, AzureRmContext, AzureCredential

Expand All @@ -64,8 +64,8 @@ Accept wildcard characters: False
The resource name.

```yaml
Type: String
Parameter Sets: ByVirtualWanName
Type: System.String
Parameter Sets: (All)
Aliases: ResourceName

Required: False
Expand All @@ -79,8 +79,8 @@ Accept wildcard characters: False
The resource group name.

```yaml
Type: String
Parameter Sets: ByVirtualWanName
Type: System.String
Parameter Sets: (All)
Aliases:

Required: True
Expand All @@ -94,7 +94,7 @@ Accept wildcard characters: False
The Azure resource ID for the virtual wan.

```yaml
Type: String
Type: System.String
Parameter Sets: ByVirtualWanResourceId
Aliases: VirtualWanId

Expand All @@ -109,7 +109,7 @@ Accept wildcard characters: False
The virtual wan object.

```yaml
Type: PSVirtualWan
Type: Microsoft.Azure.Commands.Network.Models.PSVirtualWan
Parameter Sets: ByVirtualWanObject
Aliases: VirtualWan

Expand Down
Loading