Skip to content
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

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/Network/Network.Test/Network.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Graph.RBAC" Version="3.4.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="19.20.1-preview" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="19.21.0-preview" />
<PackageReference Include="Microsoft.Azure.Insights" Version="0.16.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="35.1.0" />
<PackageReference Include="Microsoft.Azure.Management.ContainerInstance" Version="2.0.0" />
Expand Down
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
3 changes: 3 additions & 0 deletions src/Network/Network/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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
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 }); }
}
}
}
4 changes: 2 additions & 2 deletions 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 All @@ -14,7 +14,7 @@

<ItemGroup>
<PackageReference Include="AutoMapper" Version="6.2.2" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="19.20.1-preview" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="19.21.0-preview" />
</ItemGroup>

<ItemGroup>
Expand Down