Skip to content

Commit 0c20b5b

Browse files
authored
add validation check for mixed lb and as membership (#142)
1 parent 2b756ee commit 0c20b5b

File tree

3 files changed

+235
-2
lines changed

3 files changed

+235
-2
lines changed

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.23'
15+
ModuleVersion = '2.4.24'
1616

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

109109
# ReleaseNotes of this module
110-
ReleaseNotes = 'Added support for basic LBs with no child resources.'
110+
ReleaseNotes = 'Added validation check for VM mixed LB backend pool and availability set membership.'
111111

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

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,28 @@ Function Test-SupportedMigrationScenario {
578578
}
579579
}
580580
}
581+
582+
# check if backend VMs are part of an Availability Set and if there are other members of the same availability set which are not part of the load balancer backend pool or inbound nat pools
583+
log -Message "[Test-SupportedMigrationScenario] Checking if backend VMs are part of an Availability Set and if there are other members of the same availability set which are not part of the load balancer backend pool..."
584+
$availabilitySetVMs = @()
585+
$availabilitySetReference = $basicLBVMs | Where-Object { $_.AvailabilitySetReference -ne $null } | Select-Object -ExpandProperty AvailabilitySetReference
586+
587+
If (![string]::IsNullOrEmpty($availabilitySetReference)) {
588+
$availabilitySetVMs = $availabilitySetReference | Get-Unique | Get-AzResource | Get-AzAvailabilitySet | Select-Object -expand VirtualMachinesReferences | Select-Object -ExpandProperty Id
589+
$availabilitySetVMs = $availabilitySetVMs | Sort-Object | Get-Unique
590+
$extraAvailabilitySetVMs = $availabilitySetVMs | Where-Object { $_ -notin $basicLBVMs.Id } | Sort-Object | Get-Unique
591+
592+
If ($extraAvailabilitySetVMs) {
593+
$message = "[Test-SupportedMigrationScenario] VMs ('$($extraAvailabilitySetVMs -join ';')') are part of an Availability Set and there are other members of the same Availability Set which are part of the load balancer backend pools. This is not supported for migration. To work around this, create a new backend pool on the basic LB which is not associated with a load balancing rule and add the extra VMs to it temporarily, then retry migration."
594+
log -Message $message -Severity 'Error' -terminateOnError
595+
}
596+
Else {
597+
log -Message "[Test-SupportedMigrationScenario] No extra Availability Set VMs found" -Severity Information
598+
}
599+
}
600+
Else {
601+
log -Message "[Test-SupportedMigrationScenario] No Availability Sets found" -Severity Information
602+
}
581603
}
582604

583605

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
targetScope = 'subscription'
2+
param location string
3+
param resourceGroupName string
4+
param randomGuid string = newGuid()
5+
6+
// Resource Group
7+
module rg '../modules/Microsoft.Resources/resourceGroups/deploy.bicep' = {
8+
name: '${resourceGroupName}-${location}'
9+
params: {
10+
name: resourceGroupName
11+
location: location
12+
}
13+
}
14+
15+
// vnet
16+
module virtualNetworks '../modules/Microsoft.Network/virtualNetworks/deploy.bicep' = {
17+
name: '${uniqueString(deployment().name)}-virtualNetworks'
18+
scope: resourceGroup(resourceGroupName)
19+
params: {
20+
// Required parameters
21+
location: location
22+
addressPrefixes: [
23+
'10.0.0.0/16'
24+
]
25+
name: 'vnet-01'
26+
subnets: [
27+
{
28+
name: 'subnet-01'
29+
addressPrefix: '10.0.1.0/24'
30+
}
31+
]
32+
}
33+
dependsOn: [
34+
rg
35+
]
36+
}
37+
38+
module publicIp01 '../modules/Microsoft.Network/publicIPAddresses/deploy.bicep' = {
39+
name: 'pip-01'
40+
params: {
41+
name: 'pip-01'
42+
location: location
43+
publicIPAddressVersion: 'IPv4'
44+
skuTier: 'Regional'
45+
skuName: 'Basic'
46+
publicIPAllocationMethod: 'Dynamic'
47+
}
48+
scope: resourceGroup(resourceGroupName)
49+
dependsOn: [
50+
rg
51+
]
52+
}
53+
54+
// basic lb
55+
module loadbalancer '../modules/Microsoft.Network/loadBalancers_custom/deploy.bicep' = {
56+
name: 'lb-basic01'
57+
scope: resourceGroup(resourceGroupName)
58+
params: {
59+
name: 'lb-basic-01'
60+
location: location
61+
frontendIPConfigurations: [
62+
{
63+
name: 'fe-01'
64+
publicIPAddressId: publicIp01.outputs.resourceId
65+
}
66+
]
67+
backendAddressPools: [
68+
{
69+
name: 'be-01'
70+
}
71+
]
72+
inboundNatRules: []
73+
loadBalancerSku: 'Basic'
74+
loadBalancingRules: [
75+
{
76+
backendAddressPoolName: 'be-01'
77+
backendPort: 80
78+
frontendIPConfigurationName: 'fe-01'
79+
frontendPort: 80
80+
idleTimeoutInMinutes: 4
81+
loadDistribution: 'Default'
82+
name: 'rule-01'
83+
probeName: 'probe-01'
84+
protocol: 'Tcp'
85+
}
86+
]
87+
probes: [
88+
{
89+
intervalInSeconds: 5
90+
name: 'probe-01'
91+
numberOfProbes: 2
92+
port: '80'
93+
protocol: 'Tcp'
94+
}
95+
]
96+
}
97+
dependsOn: [
98+
rg
99+
]
100+
}
101+
102+
module storageAccounts '../modules/Microsoft.Storage/storageAccounts/deploy.bicep' = {
103+
name: 'bootdiag-storage-01'
104+
scope: resourceGroup(resourceGroupName)
105+
params: {
106+
name: 'bootdiag${uniqueString(deployment().name)}'
107+
location: location
108+
storageAccountSku: 'Standard_LRS'
109+
storageAccountKind: 'StorageV2'
110+
supportsHttpsTrafficOnly: true
111+
}
112+
dependsOn: [
113+
rg
114+
]
115+
}
116+
117+
module availabilitySet '../modules/Microsoft.Compute/availabilitySets/deploy.bicep' = {
118+
scope: resourceGroup(resourceGroupName)
119+
name: 'as-01'
120+
params: {
121+
location: location
122+
name: 'as-01'
123+
}
124+
dependsOn: [
125+
rg
126+
]
127+
}
128+
129+
module vm '../modules/Microsoft.Compute/virtualMachines_custom/deploy.bicep' = {
130+
scope: resourceGroup(resourceGroupName)
131+
name: 'vm-01'
132+
params: {
133+
name: 'vm-01'
134+
adminUsername: 'admin-vm'
135+
adminPassword: '${uniqueString(randomGuid)}rpP@340'
136+
availabilitySetResourceId: availabilitySet.outputs.resourceId
137+
location: location
138+
imageReference: {
139+
offer: 'WindowsServer'
140+
publisher: 'MicrosoftWindowsServer'
141+
sku: '2022-Datacenter'
142+
version: 'latest'
143+
}
144+
nicConfigurations: [
145+
{
146+
location: location
147+
ipConfigurations: [
148+
{
149+
name: 'ipconfig1'
150+
subnetResourceId: virtualNetworks.outputs.subnetResourceIds[0]
151+
loadBalancerBackendAddressPools: [
152+
{
153+
id: loadbalancer.outputs.backendpools[0].id
154+
}
155+
]
156+
}
157+
]
158+
nicSuffix: 'nic'
159+
}
160+
]
161+
osDisk: {
162+
createOption: 'fromImage'
163+
diskSizeGB: '128'
164+
managedDisk: {
165+
storageAccountType: 'Standard_LRS'
166+
}
167+
}
168+
osType: 'Windows'
169+
vmSize: 'Standard_DS1_v2'
170+
}
171+
}
172+
173+
module vm2 '../modules/Microsoft.Compute/virtualMachines_custom/deploy.bicep' = {
174+
scope: resourceGroup(resourceGroupName)
175+
name: 'vm-02'
176+
params: {
177+
name: 'vm-02'
178+
adminUsername: 'admin-vm'
179+
availabilitySetResourceId: availabilitySet.outputs.resourceId
180+
adminPassword: '${uniqueString(randomGuid)}rpP@340'
181+
location: location
182+
imageReference: {
183+
offer: 'WindowsServer'
184+
publisher: 'MicrosoftWindowsServer'
185+
sku: '2022-Datacenter'
186+
version: 'latest'
187+
}
188+
nicConfigurations: [
189+
{
190+
location: location
191+
ipConfigurations: [
192+
{
193+
name: 'ipconfig1'
194+
subnetResourceId: virtualNetworks.outputs.subnetResourceIds[0]
195+
loadBalancerBackendAddressPools: []
196+
}
197+
]
198+
nicSuffix: 'nic'
199+
}
200+
]
201+
osDisk: {
202+
createOption: 'fromImage'
203+
diskSizeGB: '128'
204+
managedDisk: {
205+
storageAccountType: 'Standard_LRS'
206+
}
207+
}
208+
osType: 'Windows'
209+
vmSize: 'Standard_DS1_v2'
210+
}
211+
}

0 commit comments

Comments
 (0)