Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'AzureAvSetBasicPublicIPUpgrade'

# Version number of this module.
ModuleVersion = '1.0.0'
ModuleVersion = '1.0.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -107,7 +107,7 @@ PrivateData = @{
# IconUri = ''

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

# Prerelease string of this module
# Prerelease = ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ Function Start-AzAvSetPublicIPUpgrade {
}

If ($VM.publicIPIPConfigAssociations.count -lt 1) {
Add-LogEntry "VM '$($VM.vmObject.Name)' does not have any public IP addresses attached. Skipping upgrade." -severity WARNING
return
Add-LogEntry "VM '$($VM.vmObject.Name)' does not have any public IP addresses attached. Skipping upgrading this VM." -severity INFO
$VMs = $VMs | Where-Object { $_.vmObject.Id -ne $VM.vmObject.Id }
Copy link

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifying the collection being iterated over during a foreach loop can lead to unexpected behavior. The VM should be filtered out before the loop or the loop should be restructured to avoid modifying the collection during iteration.

Suggested change
$VMs = $VMs | Where-Object { $_.vmObject.Id -ne $VM.vmObject.Id }

Copilot uses AI. Check for mistakes.
continue
}
Else {
Add-LogEntry "VM '$($VM.vmObject.Name)' has $($VM.publicIPIPConfigAssociations.count) public IP addresses attached."
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
targetScope = 'subscription'
param location string
param resourceGroupName string
param randomGuid string = newGuid()

// Resource Group
module rg '../modules/Microsoft.Resources/resourceGroups/deploy.bicep' = {
name: '${resourceGroupName}-${location}'
params: {
name: resourceGroupName
location: location
}
}

// vnet
module virtualNetworks '../modules/Microsoft.Network/virtualNetworks/deploy.bicep' = {
name: '${uniqueString(deployment().name)}-virtualNetworks'
scope: resourceGroup(resourceGroupName)
params: {
// Required parameters
location: location
addressPrefixes: [
'10.0.0.0/16'
]
name: 'vnet-01'
subnets: [
{
name: 'subnet-01'
addressPrefix: '10.0.1.0/24'
}
]
}
dependsOn: [
rg
]
}

module storageAccounts '../modules/Microsoft.Storage/storageAccounts/deploy.bicep' = {
name: 'bootdiag-storage-01'
scope: resourceGroup(resourceGroupName)
params: {
name: 'bootdiag${uniqueString(deployment().name)}'
location: location
storageAccountSku: 'Standard_LRS'
storageAccountKind: 'StorageV2'
supportsHttpsTrafficOnly: true
}
dependsOn: [
rg
]
}

module nsg '../modules/Microsoft.Network/networkSecurityGroups/deploy.bicep' = {
scope: resourceGroup(resourceGroupName)
name: 'nsg-01'
params: {
name: 'nsg-01'
location: location
}
dependsOn: [ rg ]
}

module availabilitySets '../modules/Microsoft.Compute/availabilitySets/deploy.bicep' = {
scope: resourceGroup(resourceGroupName)
name: 'avset-01'
params: {
name: 'avset-01'
location: location
}
dependsOn: [
rg
]
}

module vm1 '../modules/Microsoft.Compute/virtualMachines_custom/deploy.bicep' = {
scope: resourceGroup(resourceGroupName)
name: 'vm-01'
params: {
adminUsername: 'admin-vm'
name: 'vm-01'
adminPassword: '${uniqueString(randomGuid)}rpP@340'
availabilitySetResourceId: availabilitySets.outputs.resourceId
location: location
imageReference: {
offer: 'UbuntuServer'
publisher: 'Canonical'
sku: '18.04-LTS'
Copy link

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Ubuntu 18.04 LTS reached end of standard support in May 2023. Consider using a more recent Ubuntu LTS version like '20.04-LTS' or '22.04-LTS' for better security and support.

Suggested change
sku: '18.04-LTS'
sku: '22_04-lts-gen2'

Copilot uses AI. Check for mistakes.
version: 'latest'
}
nicConfigurations: [
{
location: location
ipConfigurations: [
{
name: 'ipconfig1'
subnetResourceId: virtualNetworks.outputs.subnetResourceIds[0]
loadBalancerBackendAddressPools: []
pipConfiguration: {
publicIpNameSuffix: '-pip-01'
}
skuName: 'Basic'
networkSecurityGroup: nsg.outputs.resourceId
}

]
nicSuffix: 'nic'
enableAcceleratedNetworking: false
}
]
osDisk: {
createOption: 'fromImage'
diskSizeGB: '128'
managedDisk: {
storageAccountType: 'Standard_LRS'
}
}
osType: 'Linux'
vmSize: 'Standard_DS1_v2'
}
}

module vm2 '../modules/Microsoft.Compute/virtualMachines_custom/deploy.bicep' = {
scope: resourceGroup(resourceGroupName)
name: 'vm-02'
params: {
name: 'vm-02'
adminUsername: 'admin-vm'
adminPassword: '${uniqueString(randomGuid)}rpP@340'
availabilitySetResourceId: availabilitySets.outputs.resourceId
location: location
imageReference: {
offer: 'UbuntuServer'
publisher: 'Canonical'
sku: '18.04-LTS'
version: 'latest'
}
nicConfigurations: [
{
location: location
ipConfigurations: [
{
name: 'ipconfig1'
subnetResourceId: virtualNetworks.outputs.subnetResourceIds[0]
loadBalancerBackendAddressPools: []
skuName: 'Basic'
networkSecurityGroup: nsg.outputs.resourceId
}
]
nicSuffix: 'nic'
enableAcceleratedNetworking: false
}
]
osDisk: {
createOption: 'fromImage'
diskSizeGB: '128'
managedDisk: {
storageAccountType: 'Standard_LRS'
}
}
osType: 'Linux'
vmSize: 'Standard_DS1_v2'
}
}
Loading