Skip to content

Commit

Permalink
fix vm validation, add multi lb scenarios (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrat2005 authored Oct 5, 2023
1 parent c1f3df9 commit 126998b
Show file tree
Hide file tree
Showing 6 changed files with 837 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'AzureBasicLoadBalancerUpgrade'

# Version number of this module.
ModuleVersion = '2.2.2'
ModuleVersion = '2.2.3'

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

# ReleaseNotes of this module
ReleaseNotes = 'Fixed an issue where NSG validation post-migration sometimes failed due to resource graph ingestion delay'
ReleaseNotes = 'Fixed an issue with validation for VM scenarios'

# Prerelease string of this module
# Prerelease = ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ Function Test-SupportedMigrationScenario {
If ($scenario.BackendType -eq 'VM') {

# create array of VMs associated with the load balancer for following checks and verify that NICs are associated to VMs
$basicLBVMs = @()
foreach ($backendAddressPool in $BasicLoadBalancer.BackendAddressPools) {
foreach ($backendIpConfiguration in $backendAddressPool.BackendIpConfigurations) {
$nic = Get-AzNetworkInterface -ResourceId ($backendIpConfiguration.Id -split '/ipconfigurations/')[0]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
targetScope = 'subscription'
param randomGuid string = newGuid()
param location string
param resourceGroupName string


// 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
]
}

// basic lb
module loadbalancer01 '../modules/Microsoft.Network/loadBalancers_custom/deploy.bicep' = {
name: 'lb-basic-01'
scope: resourceGroup(resourceGroupName)
params: {
name: 'lb-basic-01'
location: location
frontendIPConfigurations: [
{
name: 'fe-01'
subnetId: virtualNetworks.outputs.subnetResourceIds[0]
}
]
backendAddressPools: [
{
name: 'be-01'
}
]
inboundNatRules: []
loadBalancerSku: 'Basic'
loadBalancingRules: [
{
backendAddressPoolName: 'be-01'
backendPort: 80
frontendIPConfigurationName: 'fe-01'
frontendPort: 80
idleTimeoutInMinutes: 4
loadDistribution: 'Default'
name: 'rule-01'
probeName: 'probe-01'
protocol: 'Tcp'
}
]
probes: [
{
intervalInSeconds: 5
name: 'probe-01'
numberOfProbes: 2
port: '80'
protocol: 'Tcp'
}
]
}
dependsOn: [
rg
]
}

module publicIp01 '../modules/Microsoft.Network/publicIpAddresses/deploy.bicep' = {
name: 'pip-01'
params: {
name: 'pip-01'
location: location
publicIPAddressVersion: 'IPv4'
skuTier: 'Regional'
skuName: 'Basic'
publicIPAllocationMethod: 'Dynamic'
}
scope: resourceGroup(resourceGroupName)
dependsOn: [
rg
]
}

// basic lb
module loadbalancer02 '../modules/Microsoft.Network/loadBalancers_custom/deploy.bicep' = {
name: 'lb-basicext02'
scope: resourceGroup(resourceGroupName)
params: {
name: 'lb-basic-02'
location: location
frontendIPConfigurations: [
{
name: 'fe-01'
publicIPAddressId: publicIp01.outputs.resourceId
}
]
backendAddressPools: [
{
name: 'be-01'
}
]
inboundNatRules: []
loadBalancerSku: 'Basic'
loadBalancingRules: [
{
backendAddressPoolName: 'be-01'
backendPort: 80
frontendIPConfigurationName: 'fe-01'
frontendPort: 80
idleTimeoutInMinutes: 4
loadDistribution: 'Default'
name: 'rule-01'
probeName: 'probe-01'
protocol: 'Tcp'
}
]
probes: [
{
intervalInSeconds: 5
name: 'probe-01'
numberOfProbes: 2
port: '80'
protocol: 'Tcp'
}
]
}
dependsOn: [
rg
]
}


module virtualMachineScaleSets '../modules/Microsoft.Compute/virtualMachineScaleSets/deploy.bicep' = {
name: 'vmss-01'
scope: resourceGroup(resourceGroupName)
params: {
location: location
// Required parameters
encryptionAtHost: false
adminUsername: 'admin-vmss'
skuCapacity: 1
upgradePolicyMode: 'Manual'
imageReference: {
offer: 'WindowsServer'
publisher: 'MicrosoftWindowsServer'
sku: '2022-Datacenter'
version: 'latest'
}
name: 'vmss-01'
osDisk: {
createOption: 'fromImage'
diskSizeGB: '128'
managedDisk: {
storageAccountType: 'Standard_LRS'
}
}
osType: 'Windows'
skuName: 'Standard_DS1_v2'
// Non-required parameters
adminPassword: '${uniqueString(randomGuid)}rpP@340'
nicConfigurations: [
{
ipConfigurations: [
{
name: 'ipconfig1'
properties: {
subnet: {
id: virtualNetworks.outputs.subnetResourceIds[0]
}
loadBalancerBackendAddressPools: [
{
id: loadbalancer01.outputs.backendpools[0].id
}
{
id: loadbalancer02.outputs.backendpools[0].id
}
]
}
}
]
nicSuffix: '-nic-01'
}
]
}
dependsOn: [
rg
]
}

Loading

0 comments on commit 126998b

Please sign in to comment.