Skip to content

Commit 3f623aa

Browse files
Merge pull request #437 from SaleemBseeu/patch-6
Patch 6 - DDoS plan link script
2 parents ac46df9 + b192e83 commit 3f623aa

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Variables
2+
3+
$resourceGroupName = "YourResourceGroupName"
4+
5+
$ddosProtectionPlanName = "YourDdosProtectionPlanName"
6+
7+
$publicIpNames = @("PublicIP1", "PublicIP2", "PublicIP3") # Add your public IP names here
8+
9+
10+
11+
# Get the DDoS protection plan
12+
13+
$ddosProtectionPlan = Get-AzDdosProtectionPlan -ResourceGroupName $resourceGroupName -Name $ddosProtectionPlanName
14+
15+
16+
17+
# Loop through each public IP and enable DDoS protection
18+
19+
foreach ($publicIpName in $publicIpNames) {
20+
21+
# Get the public IP address
22+
23+
$publicIp = Get-AzPublicIpAddress -Name $publicIpName -ResourceGroupName $resourceGroupName
24+
25+
26+
27+
# Check if the public IP is Standard SKU
28+
29+
if ($publicIp.Sku.Name -ne "Standard") {
30+
31+
Write-Output "Skipping ${publicIpName}: DDoS protection is only supported on Standard SKU public IPs."
32+
33+
continue
34+
35+
}
36+
37+
38+
39+
# Enable DDoS protection and associate with the DDoS protection plan
40+
41+
$publicIp.DdosSettings = @{
42+
43+
ProtectionMode = "Enabled"
44+
45+
DdosProtectionPlan = @{
46+
47+
Id = $ddosProtectionPlan.Id
48+
49+
}
50+
51+
}
52+
53+
54+
55+
# Update the public IP address
56+
57+
Set-AzPublicIpAddress -PublicIpAddress $publicIp
58+
59+
60+
61+
Write-Output "DDoS protection enabled for ${publicIpName} and associated with DDoS protection plan ${ddosProtectionPlanName}."
62+
63+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
# Add Public IPs to Existing Azure DDoS Protection Plan
3+
**Author: Saleem Bseeu**
4+
5+
This PowerShell script allows users to assign the DDoS IP Protection SKU to selected Standard SKU Public IP addresses and link them to an existing Azure DDoS Network Protection plan. This is useful for selectively applying DDoS protection to only specific IPs in your environment and avoiding double billing.
6+
7+
## Example:
8+
9+
```powershell
10+
# Edit these variables with your own values
11+
$resourceGroupName = "MyResourceGroup"
12+
$ddosProtectionPlanName = "MyDdosPlan"
13+
$publicIpNames = @("PublicIP1", "PublicIP2")
14+
15+
# Run the script to enable protection and link to plan
16+
.\link-ddos-ip-protection.ps1
17+
```
18+
19+
The script will:
20+
- Verify that each Public IP is using the Standard SKU
21+
- Enable IP Protection on the Public IP if not already set
22+
- Link the Public IP to the specified DDoS Network Protection plan
23+
- Skip any IPs that are not eligible or already configured
24+
25+
## Contributing
26+
27+
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
28+
29+
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
30+
31+
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct) or contact [email protected] with any additional questions or comments.

0 commit comments

Comments
 (0)