Skip to content

Commit 80bbe1e

Browse files
authored
fix avset mixed vm pip no pip upgrade (#160)
1 parent a10dbbf commit 80bbe1e

File tree

3 files changed

+168
-4
lines changed

3 files changed

+168
-4
lines changed

AzureAvSetBasicPublicIPUpgrade/module/AzureAvSetBasicPublicIPUpgrade/AzureAvSetBasicPublicIPUpgrade.psd1

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

1414
# Version number of this module.
15-
ModuleVersion = '1.0.0'
15+
ModuleVersion = '1.0.1'
1616

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

109109
# ReleaseNotes of this module
110-
ReleaseNotes = 'NSG detection improvements, recovery fixes'
110+
ReleaseNotes = 'Fix mixed VM/PIP scenario handling'
111111

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

AzureAvSetBasicPublicIPUpgrade/module/AzureAvSetBasicPublicIPUpgrade/AzureAvSetBasicPublicIPUpgrade.psm1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,9 @@ Function Start-AzAvSetPublicIPUpgrade {
220220
}
221221

222222
If ($VM.publicIPIPConfigAssociations.count -lt 1) {
223-
Add-LogEntry "VM '$($VM.vmObject.Name)' does not have any public IP addresses attached. Skipping upgrade." -severity WARNING
224-
return
223+
Add-LogEntry "VM '$($VM.vmObject.Name)' does not have any public IP addresses attached. Skipping upgrading this VM." -severity INFO
224+
$VMs = $VMs | Where-Object { $_.vmObject.Id -ne $VM.vmObject.Id }
225+
continue
225226
}
226227
Else {
227228
Add-LogEntry "VM '$($VM.vmObject.Name)' has $($VM.publicIPIPConfigAssociations.count) public IP addresses attached."
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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 storageAccounts '../modules/Microsoft.Storage/storageAccounts/deploy.bicep' = {
39+
name: 'bootdiag-storage-01'
40+
scope: resourceGroup(resourceGroupName)
41+
params: {
42+
name: 'bootdiag${uniqueString(deployment().name)}'
43+
location: location
44+
storageAccountSku: 'Standard_LRS'
45+
storageAccountKind: 'StorageV2'
46+
supportsHttpsTrafficOnly: true
47+
}
48+
dependsOn: [
49+
rg
50+
]
51+
}
52+
53+
module nsg '../modules/Microsoft.Network/networkSecurityGroups/deploy.bicep' = {
54+
scope: resourceGroup(resourceGroupName)
55+
name: 'nsg-01'
56+
params: {
57+
name: 'nsg-01'
58+
location: location
59+
}
60+
dependsOn: [ rg ]
61+
}
62+
63+
module availabilitySets '../modules/Microsoft.Compute/availabilitySets/deploy.bicep' = {
64+
scope: resourceGroup(resourceGroupName)
65+
name: 'avset-01'
66+
params: {
67+
name: 'avset-01'
68+
location: location
69+
}
70+
dependsOn: [
71+
rg
72+
]
73+
}
74+
75+
module vm1 '../modules/Microsoft.Compute/virtualMachines_custom/deploy.bicep' = {
76+
scope: resourceGroup(resourceGroupName)
77+
name: 'vm-01'
78+
params: {
79+
adminUsername: 'admin-vm'
80+
name: 'vm-01'
81+
adminPassword: '${uniqueString(randomGuid)}rpP@340'
82+
availabilitySetResourceId: availabilitySets.outputs.resourceId
83+
location: location
84+
imageReference: {
85+
offer: 'UbuntuServer'
86+
publisher: 'Canonical'
87+
sku: '18.04-LTS'
88+
version: 'latest'
89+
}
90+
nicConfigurations: [
91+
{
92+
location: location
93+
ipConfigurations: [
94+
{
95+
name: 'ipconfig1'
96+
subnetResourceId: virtualNetworks.outputs.subnetResourceIds[0]
97+
loadBalancerBackendAddressPools: []
98+
pipConfiguration: {
99+
publicIpNameSuffix: '-pip-01'
100+
}
101+
skuName: 'Basic'
102+
networkSecurityGroup: nsg.outputs.resourceId
103+
}
104+
105+
]
106+
nicSuffix: 'nic'
107+
enableAcceleratedNetworking: false
108+
}
109+
]
110+
osDisk: {
111+
createOption: 'fromImage'
112+
diskSizeGB: '128'
113+
managedDisk: {
114+
storageAccountType: 'Standard_LRS'
115+
}
116+
}
117+
osType: 'Linux'
118+
vmSize: 'Standard_DS1_v2'
119+
}
120+
}
121+
122+
module vm2 '../modules/Microsoft.Compute/virtualMachines_custom/deploy.bicep' = {
123+
scope: resourceGroup(resourceGroupName)
124+
name: 'vm-02'
125+
params: {
126+
name: 'vm-02'
127+
adminUsername: 'admin-vm'
128+
adminPassword: '${uniqueString(randomGuid)}rpP@340'
129+
availabilitySetResourceId: availabilitySets.outputs.resourceId
130+
location: location
131+
imageReference: {
132+
offer: 'UbuntuServer'
133+
publisher: 'Canonical'
134+
sku: '18.04-LTS'
135+
version: 'latest'
136+
}
137+
nicConfigurations: [
138+
{
139+
location: location
140+
ipConfigurations: [
141+
{
142+
name: 'ipconfig1'
143+
subnetResourceId: virtualNetworks.outputs.subnetResourceIds[0]
144+
loadBalancerBackendAddressPools: []
145+
skuName: 'Basic'
146+
networkSecurityGroup: nsg.outputs.resourceId
147+
}
148+
]
149+
nicSuffix: 'nic'
150+
enableAcceleratedNetworking: false
151+
}
152+
]
153+
osDisk: {
154+
createOption: 'fromImage'
155+
diskSizeGB: '128'
156+
managedDisk: {
157+
storageAccountType: 'Standard_LRS'
158+
}
159+
}
160+
osType: 'Linux'
161+
vmSize: 'Standard_DS1_v2'
162+
}
163+
}

0 commit comments

Comments
 (0)