Skip to content

Commit a41d4d0

Browse files
authored
Fix Multi LB Config Name Validation (#100)
* remove IP conversion warnings * remove unnecessary update when no NAT pools * add and fix nat scenarios * fixed as rg dependency * renamed backup module * added nat pool migration function * support for nat rule only configs * comment clarity * nat pool migration with emtpy backend * nat rule ipconfig migration * nat pool migration validation and param changes * remove vmss from scenario validation * add NVA to outbound options * remove resource graph module check * move to single line error message * added Learn doc link * fix multi lb name validation * version bump
1 parent eb1b960 commit a41d4d0

File tree

4 files changed

+30
-62
lines changed

4 files changed

+30
-62
lines changed

AzureBasicLoadBalancerUpgrade/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Upgrade a basic load balancer with PowerShell
22

3+
[**Microsoft Learn Documentation**](https://learn.microsoft.com/azure/load-balancer/upgrade-basic-standard-with-powershell)
4+
35
>[!Important]
46
>On September 30, 2025, Basic Load Balancer will be retired. For more information, see the [official announcement](https://azure.microsoft.com/updates/azure-basic-load-balancer-will-be-retired-on-30-september-2025-upgrade-to-standard-load-balancer/). If you are currently using Basic Load Balancer, make sure to upgrade to Standard Load Balancer prior to the retirement date.
57

AzureBasicLoadBalancerUpgrade/module/AzureBasicLoadBalancerUpgrade/AzureBasicLoadBalancerUpgrade.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'AzureBasicLoadBalancerUpgrade'
1313

1414
# Version number of this module.
15-
ModuleVersion = '2.4.0'
15+
ModuleVersion = '2.4.1'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()
@@ -107,7 +107,7 @@
107107
# IconUri = ''
108108

109109
# ReleaseNotes of this module
110-
ReleaseNotes = 'Fix NAT Rule backend migration, Add NAT Pool to NAT Rule migration'
110+
ReleaseNotes = 'Fix multi-LB name validation'
111111

112112
# Prerelease string of this module
113113
# Prerelease = ''

AzureBasicLoadBalancerUpgrade/module/AzureBasicLoadBalancerUpgrade/modules/Start-AzBasicLoadBalancerUpgrade/Start-AzBasicLoadBalancerUpgrade.psm1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,7 @@ function Start-AzBasicLoadBalancerUpgrade {
248248
}
249249
}
250250
catch {
251-
$message = @"
252-
[Start-AzBasicLoadBalancerUpgrade] Failed to find basic load balancer '$BasicLoadBalancerName' in resource group '$ResourceGroupName' under subscription
253-
'$((Get-AzContext).Subscription.Name)'. Ensure that the correct subscription is selected and verify the load balancer and resource group names.
254-
Error text: $_
255-
"@
251+
$message = "[Start-AzBasicLoadBalancerUpgrade] Failed to find basic load balancer '$BasicLoadBalancerName' in resource group '$ResourceGroupName' under subscription '$((Get-AzContext).Subscription.Name)'. Ensure that the correct subscription is selected and verify the load balancer and resource group names. Error text: $_"
256252
log -severity Error -message $message -terminateOnError
257253
}
258254

@@ -289,11 +285,10 @@ function Start-AzBasicLoadBalancerUpgrade {
289285
ElseIf ($PSCmdlet.ParameterSetName -eq 'MultiLB') {
290286
log -Message "[Start-AzBasicLoadBalancerUpgrade] -MultiLBConfig parameter set detected, validating scenarios for multiple load balancers"
291287

292-
# verify the scenario for multi-load balancer configurations
293-
Test-SupportedMultiLBScenario -MultiLBConfig $multiLBConfig
294-
295288
# verify scenario for each load balancer in the multiLBConfig array
296289
ForEach ($LBConfig in $multiLBConfig) {
290+
291+
# set standard LB name if none is specified
297292
if (![string]::IsNullOrEmpty($LBConfig.standardLoadBalancerName)) {
298293
$StdLoadBalancerName = $LBConfig.standardLoadBalancerName
299294
}
@@ -310,6 +305,9 @@ function Start-AzBasicLoadBalancerUpgrade {
310305
# add the evaluated scenario details to the LBConfig object
311306
$LBConfig['scenario'] = $scenario
312307
}
308+
309+
# verify the scenario for multi-load balancer configurations
310+
Test-SupportedMultiLBScenario -MultiLBConfig $multiLBConfig
313311

314312
if ($validateScenarioOnly) {
315313
log -Message "[Start-AzBasicLoadBalancerUpgrade] Scenario validation completed, exiting because -validateScenarioOnly was specified"
@@ -366,6 +364,8 @@ function Start-AzBasicLoadBalancerUpgrade {
366364
}
367365
}
368366
'VMSS' {
367+
$standardScenarioParams += @{skipMigrateNATPoolsToNATRules = $skipMigrateNATPoolsToNATRules.IsPresent}
368+
369369
switch ($migrationConfig.scenario.ExternalOrInternal) {
370370
'internal' {
371371
if ((!$PSBoundParameters.ContainsKey("FailedMigrationRetryFilePathLB"))) {

AzureBasicLoadBalancerUpgrade/module/AzureBasicLoadBalancerUpgrade/modules/ValidateScenario/ValidateScenario.psm1

Lines changed: 18 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,7 @@ Function Test-SupportedMigrationScenario {
225225

226226
ForEach ($instance in $vmssInstances) {
227227
If ($instance.ProtectionPolicy.ProtectFromScaleSetActions) {
228-
$message = @"
229-
[Test-SupportedMigrationScenario] VMSS '$($vmss.Name)' contains 1 or more instances with a ProtectFromScaleSetActions Instance Protection configured. This
230-
module cannot upgrade the associated load balancer because a VMSS cannot be a backend member of both basic and standard SKU load balancers. Remove the Instance
231-
Protection policy and re-run the module.
232-
"@
228+
$message = "[Test-SupportedMigrationScenario] VMSS '$($vmss.Name)' contains 1 or more instances with a ProtectFromScaleSetActions Instance Protection configured. This module cannot upgrade the associated load balancer because a VMSS cannot be a backend member of both basic and standard SKU load balancers. Remove the Instance Protection policy and re-run the module."
233229
log -Severity 'Error'
234230
$vmssInstances.Remove($instance)
235231
}
@@ -490,7 +486,7 @@ Function Test-SupportedMigrationScenario {
490486
$message = "[Test-SupportedMigrationScenario] Internal load balancer backend VMs do not have Public IPs and will not have outbound internet connectivity after migration to a Standard LB."
491487
log -Message $message -Severity 'Warning'
492488

493-
Write-Host "In order for your VMs to access the internet, you'll need to take additional action post-migration. Either add Public IPs to each VM or assign a NAT Gateway to the VM subnet (see: https://learn.microsoft.com/en-us/azure/virtual-network/ip-services/default-outbound-access)." -ForegroundColor Yellow
489+
Write-Host "In order for your VMs to access the internet, you'll need to take additional action before or after migration. Either add Public IPs to each VM, assign a NAT Gateway to the VM subnet, or route internet traffic through an NVA (see: https://learn.microsoft.com/en-us/azure/virtual-network/ip-services/default-outbound-access)." -ForegroundColor Yellow
494490
If (!$force.IsPresent) {
495491
$response = $null
496492
while ($response -ne 'y' -and $response -ne 'n') {
@@ -508,49 +504,6 @@ Function Test-SupportedMigrationScenario {
508504
}
509505
}
510506

511-
# check that Az.ResourceGraph module is installed for VM migrations
512-
If ($scenario.BackendType -eq 'VM' -and !(Get-Module -Name Az.ResourceGraph -ListAvailable)) {
513-
$message = "[Test-SupportedMigrationScenario] Migrating Load Balancers with VM backends requires the Az.ResourceGraph module, but the module was not found."
514-
log -Message $message -Severity 'Warning'
515-
516-
If (!$force.IsPresent) {
517-
Write-Host "Migrating Load Balancers with VM backends requires the Az.ResourceGraph module, but the module was not found to be installed." -ForegroundColor Yellow
518-
$response = $null
519-
while ($response -ine 'y' -and $response -ine 'n') {
520-
$response = Read-Host -Prompt "Do you want the script to install the Az.ResourceGraph module for the current user? (y/n)"
521-
}
522-
If ($response -ieq 'n') {
523-
$message = "[Test-SupportedMigrationScenario] User chose to exit the module"
524-
log -Message $message -Severity 'Error' -terminateOnError
525-
}
526-
}
527-
528-
If ($response -ieq 'y' -or $force.IsPresent) {
529-
530-
Write-Host "Installing the Az.ResourceGraph module in the CurrentUser scope..."
531-
532-
$message = "[Test-SupportedMigrationScenario] Installing the Az.ResourceGraph module in the CurrentUser scope..."
533-
log -Message $message
534-
535-
try {
536-
$ErrorActionPreference = 'Stop'
537-
Install-Module -Name Az.ResourceGraph -Scope CurrentUser -Force
538-
}
539-
catch {
540-
$message = "[Test-SupportedMigrationScenario] Failed to install the Az.ResourceGraph module. Please install manually and re-run the script."
541-
log -Message $message -Severity 'Error' -terminateOnError
542-
}
543-
544-
Write-Host "Installing the Az.ResourceGraph module completed successfully."
545-
546-
$message = "[Test-SupportedMigrationScenario] Installing the Az.ResourceGraph module completed successfully."
547-
log -Message $message
548-
}
549-
}
550-
Else {
551-
$message = "[Test-SupportedMigrationScenario] The Az.ResourceGraph module is already installed..."
552-
log -Message $message
553-
}
554507

555508
# if the basic lb is external and has multiple backend pools, warn that the migration will not create a default outbound rule
556509
If ($scenario.ExternalOrInternal -eq 'External' -and $BasicLoadBalancer.BackendAddressPools.Count -gt 1 -and
@@ -578,7 +531,7 @@ Function Test-SupportedMigrationScenario {
578531
}
579532
}
580533

581-
Write-Progress -Status "Finished VMSS backend scenario validation" -PercentComplete 100 @progressParams
534+
Write-Progress -Status "Finished scenario validation" -PercentComplete 100 @progressParams
582535

583536
log -Message "[Test-SupportedMigrationScenario] Detected migration scenario: $($scenario | ConvertTo-Json -Depth 10 -Compress)"
584537
log -Message "[Test-SupportedMigrationScenario] Load Balancer '$($BasicLoadBalancer.Name)' is valid for migration"
@@ -597,11 +550,24 @@ Function Test-SupportedMultiLBScenario {
597550
# check that standard load balancer names are different if basic load balancers are in the same resource group
598551
log -Message "[Test-SupportedMultiLBScenario] Checking that standard load balancer names are different if basic load balancers are in the same resource group"
599552

553+
# check standard load balancer names will be unique in the same resource group
600554
ForEach ($config in $multiLBConfig) {
601555
$matchingConfigs = @()
602-
$matchingConfigs += $multiLBConfig | Where-Object { $_.StandardLoadBalancerName -eq $config.StandardLoadBalancerName -and $_.BasicLoadBalancer.ResourceGroupName -eq $config.BasicLoadBalancer.ResourceGroupName }
556+
557+
If ([string]::IsNullOrEmpty) {
558+
$StdLoadBalancerName = $config.BasicLoadBalancer.Name
559+
}
560+
Else {
561+
$StdLoadBalancerName = $config.StandardLoadBalancerName
562+
}
563+
564+
$matchingConfigs += $multiLBConfig | Where-Object {
565+
(([string]::IsNullOrEmpty($_.StandardLoadBalancerName) -and $_.BasicLoadBalancer.Name -eq $StdLoadBalancerName) -or
566+
($_.StandardLoadBalancerName -eq $StdLoadBalancerName)) -and
567+
($_.BasicLoadBalancer.ResourceGroupName -eq $config.BasicLoadBalancer.ResourceGroupName) }
568+
603569
If ($matchingConfigs.count -gt 1) {
604-
log -Severity Error -Message "[Test-SupportedMultiLBScenario] Standard Load Balancer name '$($config.StandardLoadBalancerName)' is used more than once in resource group '$($config.BasicLoadBalancer.ResourceGroupName)'. Standard Load Balancer names must be unique in the same resource group." -terminateOnError
570+
log -Severity Error -Message "[Test-SupportedMultiLBScenario] Standard Load Balancer name '$($StdLoadBalancerName)' will be used more than once in resource group '$($config.BasicLoadBalancer.ResourceGroupName)'. Standard Load Balancer names must be unique in the same resource group. If renaming load balancers with the -standardLoadBalancerName parameter, make sure new names are unique." -terminateOnError
605571
}
606572
}
607573

0 commit comments

Comments
 (0)