Skip to content

Commit 08c9663

Browse files
mchakkaManas Chakka
andauthored
DDoS Per-IP SKU Bundle Mode Support (#20456)
* another change * everything * current changes * merge * adding mapping to support older PIPs with no ddosSettings Also removed /ddosprotstatus from test * removing all /ddosprotstatus stuff * added change log * adding help Co-authored-by: Manas Chakka <[email protected]>
1 parent 1d339a3 commit 08c9663

File tree

7 files changed

+1217
-368
lines changed

7 files changed

+1217
-368
lines changed

src/Network/Network.Test/ScenarioTests/PublicIpAddressTests.ps1

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -613,17 +613,18 @@ function Test-PublicIpAddressCRUD-DdosProtection
613613
$rgname = Get-ResourceGroupName
614614
$rname = Get-ResourceName
615615
$domainNameLabel = Get-ResourceName
616+
$ddosProtectionPlanName = Get-ResourceName
616617
$rglocation = Get-ProviderLocation ResourceManagement
617618
$resourceTypeParent = "Microsoft.Network/publicIpAddresses"
618619
$location = Get-ProviderLocation $resourceTypeParent
619-
620+
620621
try
621622
{
622623
# Create the resource group
623624
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
624625

625-
# Create publicIpAddres
626-
$actual = New-AzPublicIpAddress -ResourceGroupName $rgname -name $rname -location $location -AllocationMethod Static -Sku Standard -DomainNameLabel $domainNameLabel -DdosProtectionMode "Enabled"
626+
# Create publicIpAddress
627+
$actual = New-AzPublicIpAddress -ResourceGroupName $rgname -name $rname -location $location -AllocationMethod Static -Sku Standard -DdosProtectionMode "Enabled"
627628
$expected = Get-AzPublicIpAddress -ResourceGroupName $rgname -name $rname
628629
Assert-AreEqual $expected.ResourceGroupName $actual.ResourceGroupName
629630
Assert-AreEqual $expected.Name $actual.Name
@@ -646,6 +647,17 @@ function Test-PublicIpAddressCRUD-DdosProtection
646647
Assert-AreEqual "Succeeded" $list[0].ProvisioningState
647648
Assert-AreEqual "Enabled" $expected.DdosSettings.ProtectionMode
648649

650+
#create ddos protection plan
651+
$ddpp = New-AzDdosProtectionPlan -Name $ddosProtectionPlanName -ResourceGroupName $rgname -Location $location
652+
653+
# attach plan to pip
654+
$actual.DdosSettings.DdosProtectionPlan = New-Object Microsoft.Azure.Commands.Network.Models.PSResourceId
655+
$actual.DdosSettings.DdosProtectionPlan.Id = $ddpp.Id
656+
$pip = Set-AzPublicIpAddress -PublicIpAddress $actual
657+
658+
$pip = Get-AzPublicIpAddress -ResourceGroupName $rgname -name $rname
659+
Assert-AreEqual $ddpp.Id $pip.DdosSettings.DdosProtectionPlan.Id
660+
649661
# delete
650662
$delete = Remove-AzPublicIpAddress -ResourceGroupName $actual.ResourceGroupName -name $rname -PassThru -Force
651663
Assert-AreEqual true $delete

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.PublicIpAddressTests/TestPublicIpDdosProtection.json

Lines changed: 1162 additions & 361 deletions
Large diffs are not rendered by default.

src/Network/Network/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
--->
2020

2121
## Upcoming Release
22+
* Added `DdosProtectionPlan` property in `AzPublicIpAddress`
23+
* Updated mapping in `AzPublicIpAddress` to always show/create DdosSettings
2224
* Fixed a bug that added Ddos related properties when viewing PublicIpAddress and DdosProtectionPlan objects
2325
* Fixed a Bug for Set-AzIpGroup cmdlet to support the -whatif parameter
2426
* Fixed a Bug for `Add-AzLoadBalancerFrontendIpConfig`, `Add-AzLoadBalancerProbeConfig`, `Add-AzLoadBalancerBackendAddressPoolConfig`, `Set-AzLoadBalancer`, `New-AzLoadBalancerRuleConfig`, `Remove-AzLoadBalancerInboundNatRuleConfig` cmdlets to support the `-whatif` parameter. Fix [#20416]

src/Network/Network/Common/NetworkResourceManagerProfile.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,11 @@ private static void Initialize()
407407
.ForMember(
408408
dest => dest.ExtendedLocation,
409409
opt => opt.MapFrom(src =>
410-
(src.ExtendedLocation == null ? null : new PSExtendedLocation(src.ExtendedLocation.Name)))
410+
src.ExtendedLocation == null ? null : new PSExtendedLocation(src.ExtendedLocation.Name)))
411+
.ForMember(
412+
dest => dest.DdosSettings,
413+
opt => opt.MapFrom(src =>
414+
(src.DdosSettings ?? new MNM.DdosSettings()))
411415
);
412416
cfg.CreateMap<MNM.IpTag, CNM.PSPublicIpTag>();
413417
cfg.CreateMap<MNM.PublicIPAddressSku, CNM.PSPublicIpAddressSku>();

src/Network/Network/Models/PSDdosSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@ public partial class PSDdosSettings
2020
{
2121
[Ps1Xml(Target = ViewControl.Table)]
2222
public string ProtectionMode { get; set; }
23+
24+
public PSResourceId DdosProtectionPlan { get; set; }
25+
2326
}
2427
}

src/Network/Network/PublicIpAddress/NewAzurePublicIpAddressCommand.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ public class NewAzurePublicIpAddressCommand : PublicIpAddressBaseCmdlet
138138
[ValidateNotNullOrEmpty]
139139
public string DdosProtectionMode { get; set; }
140140

141+
[Parameter(
142+
Mandatory = false,
143+
ValueFromPipelineByPropertyName = true,
144+
HelpMessage = "The DdosProtectionPlan id to attach to the Public IP address")]
145+
[ValidateNotNullOrEmpty]
146+
public string DdosProtectionPlanId { get; set; }
147+
141148
[Parameter(
142149
Mandatory = false,
143150
ValueFromPipelineByPropertyName = true,
@@ -219,6 +226,11 @@ private PSPublicIpAddress CreatePublicIpAddress()
219226
{
220227
publicIp.DdosSettings = new PSDdosSettings();
221228
publicIp.DdosSettings.ProtectionMode = this.DdosProtectionMode;
229+
230+
if (!string.IsNullOrEmpty(DdosProtectionPlanId))
231+
{
232+
publicIp.DdosSettings.DdosProtectionPlan = new PSResourceId { Id = DdosProtectionPlanId };
233+
}
222234
}
223235

224236
if (!string.IsNullOrEmpty(this.Tier))

src/Network/Network/help/New-AzPublicIpAddress.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Creates a public IP address.
1717
New-AzPublicIpAddress [-Name <String>] -ResourceGroupName <String> [-Location <String>] [-EdgeZone <String>]
1818
[-Sku <String>] [-Tier <String>] -AllocationMethod <String> [-IpAddressVersion <String>]
1919
[-DomainNameLabel <String>] [-IpTag <PSPublicIpTag[]>] [-PublicIpPrefix <PSPublicIpPrefix>]
20-
[-DdosProtectionMode <String>] [-ReverseFqdn <String>] [-IdleTimeoutInMinutes <Int32>] [-Zone <String[]>]
21-
[-IpAddress <String>] [-Tag <Hashtable>] [-Force] [-AsJob] [-DefaultProfile <IAzureContextContainer>]
22-
[-WhatIf] [-Confirm] [<CommonParameters>]
20+
[-DdosProtectionMode <String>] [-DdosProtectionPlanId <String>] [-ReverseFqdn <String>]
21+
[-IdleTimeoutInMinutes <Int32>] [-Zone <String[]>] [-IpAddress <String>] [-Tag <Hashtable>] [-Force] [-AsJob]
22+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2323
```
2424

2525
## DESCRIPTION
@@ -144,6 +144,21 @@ Accept pipeline input: True (ByPropertyName)
144144
Accept wildcard characters: False
145145
```
146146
147+
### -DdosProtectionPlanId
148+
The DdosProtectionPlan id to attach to the Public IP address
149+
150+
```yaml
151+
Type: System.String
152+
Parameter Sets: (All)
153+
Aliases:
154+
155+
Required: False
156+
Position: Named
157+
Default value: None
158+
Accept pipeline input: True (ByPropertyName)
159+
Accept wildcard characters: False
160+
```
161+
147162
### -DefaultProfile
148163
The credentials, account, tenant, and subscription used for communication with azure.
149164

0 commit comments

Comments
 (0)