Created
September 30, 2025 04:37
-
-
Save sireza/15227b639c5e69f81522e0970fe099a5 to your computer and use it in GitHub Desktop.
Azure Load Balancer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@description('The name of the internal load balancer resource') | |
param loadBalancerName string | |
@description('Location for all resources') | |
param location string = resourceGroup().location | |
@description('The resource ID of the subnet where the load balancer will be deployed') | |
param subnetId string | |
@description('Static private IP address for the load balancer frontend') | |
param frontendPrivateIPAddress string | |
@description('Optional tags for all resources') | |
param tags object = {} | |
@description('An array of backend address pools configurations') | |
param backendAddressPools array = [ | |
{ | |
name: 'BackendPool' | |
loadBalancerBackendAddresses: [] | |
} | |
] | |
@description('An array of health probes used by the load balancer') | |
param probes array = [] | |
@description('An array of load balancing rules') | |
param loadBalancingRules array = [] | |
// Create the internal load balancer resource | |
resource loadBalancer 'Microsoft.Network/loadBalancers@2023-05-01' = { | |
name: loadBalancerName | |
location: location | |
tags: tags | |
sku: { | |
name: 'Standard' | |
tier: 'Regional' | |
} | |
properties: { | |
frontendIPConfigurations: [ | |
{ | |
name: 'FrontendIP' | |
properties: { | |
privateIPAllocationMethod: 'Static' | |
privateIPAddress: frontendPrivateIPAddress | |
subnet: { | |
id: subnetId | |
} | |
} | |
} | |
] | |
backendAddressPools: [for pool in backendAddressPools: { | |
name: pool.name | |
properties: { | |
loadBalancerBackendAddresses: pool.?loadBalancerBackendAddresses ?? [] | |
} | |
}] | |
loadBalancingRules: [for rule in loadBalancingRules: { | |
name: rule.name | |
properties: { | |
frontendIPConfiguration: { | |
id: resourceId('Microsoft.Network/loadBalancers/frontendIPConfigurations', loadBalancerName, 'FrontendIP') | |
} | |
backendAddressPool: { | |
id: resourceId('Microsoft.Network/loadBalancers/backendAddressPools', loadBalancerName, rule.backendAddressPoolName) | |
} | |
protocol: rule.protocol | |
frontendPort: rule.frontendPort | |
backendPort: rule.backendPort | |
enableFloatingIP: rule.?enableFloatingIP ?? false | |
idleTimeoutInMinutes: rule.?idleTimeoutInMinutes ?? 4 | |
probe: rule.?probeName != null ? { | |
id: resourceId('Microsoft.Network/loadBalancers/probes', loadBalancerName, rule.probeName) | |
} : null | |
loadDistribution: rule.?loadDistribution ?? 'Default' | |
} | |
}] | |
probes: [for probe in probes: { | |
name: probe.name | |
properties: { | |
protocol: probe.protocol | |
port: probe.port | |
intervalInSeconds: probe.?intervalInSeconds ?? 15 | |
numberOfProbes: probe.?numberOfProbes ?? 2 | |
requestPath: (toLower(probe.protocol) == 'http' || toLower(probe.protocol) == 'https') ? (probe.?requestPath ?? '/') : null | |
} | |
}] | |
} | |
} | |
// Output the resource ID of the load balancer | |
output loadBalancerResourceId string = loadBalancer.id | |
// Output the resource ID of the backend address pool | |
output backendAddressPoolIds array = [for (pool, i) in backendAddressPools: { | |
name: pool.name | |
id: loadBalancer.properties.backendAddressPools[i].id | |
}] | |
// Output the private IP address of the load balancer | |
output frontendPrivateIPAddress string = loadBalancer.properties.frontendIPConfigurations[0].properties.privateIPAddress |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment