skip to Main Content

A little background we would like to export all Azure resource templates (Export template) and have a way to recreate the environment if needed. (Eventually, we would like to create a new environment with the template) so I created a temp Load Balancer and exported the template and how trying to recreate it, but every time I fix one error I get another one. At this point, the Load Balancer is created but the Backend Pool does not. I was told I need to reference the server or the virtual Network (resource or module) that the server is in, but I cannot get any info on how.

Backend Servers

Server Name: dev-web01
Network Interface Name: dev-web01-Nic
IP configurations Name ipconfig1, IPv4, Primary, 10.0.0.101 (Static
Subnet Name: dev-web-Net

Server Name: dev-web02
Network Interface Name: dev-web02-Nic
IP configurations Name ipconfig1, IPv4, Primary, 10.0.0.102 (Static)
Subnet Name: dev-web-Net

param location string = 'westus2'

var loadBalancerName = 'dev-web01-LB'
var virtualNetworkName = 'dev-dev-VNET'
var subnetName = 'dev-web-Net'
var subnetRef = resourceId('Microsoft.Network/virtualNetworks/subnets', virtualNetworkName, subnetName)

resource virtualNetwork 'Microsoft.Network/virtualNetworks@2022-07-01' existing = {
  name: virtualNetworkName
}

resource loadBalancers_name 'Microsoft.Network/loadBalancers@2022-07-01' = {
  name: loadBalancerName
  location: location
  sku: {
    name: 'Standard'
    tier: 'Regional'
  }
  properties: {
    frontendIPConfigurations: [
      {
        name: 'FrontendIP'
        id: resourceId('Microsoft.Network/loadBalancers/frontendIpConfigurations', loadBalancerName, 'FrontendIP')
        properties: {
          privateIPAddress: '10.0.0.196'
          privateIPAllocationMethod: 'Static'
          subnet: {
            id: subnetRef
          }
          privateIPAddressVersion: 'IPv4'
        }
      }
    ]
    backendAddressPools: [
      {
        name: 'BackendPool'
        properties: {
          loadBalancerBackendAddresses: [
            {
              // I was told I need to point the server here? (resource or module)
              name: 'dev-web01-Nicipconfig1'
              properties: {
              }
            }
            {
              name: 'dev-web01-Nicipconfig1'
              properties: {
              }
            }
          ]
        }
      }
    ]
    loadBalancingRules: [
      {
        name: 'webport-701'
        id: resourceId('Microsoft.Network/loadBalancers/frontendIpConfigurations', loadBalancerName, 'webport-701')
        properties: {
          frontendIPConfiguration: {
            id: resourceId('Microsoft.Network/loadBalancers/frontendIpConfigurations', loadBalancerName, 'FrontendIP')
          }
          frontendPort: 701
          backendPort: 701
          enableFloatingIP: false
          idleTimeoutInMinutes: 4
          protocol: 'Tcp'
          enableTcpReset: false
          loadDistribution: 'Default'
          disableOutboundSnat: false
          backendAddressPool: {
            id: resourceId('Microsoft.Network/loadBalancers/backendAddressPools', loadBalancerName, 'BackendPool')
          }
          backendAddressPools: [
            {
              id: resourceId('Microsoft.Network/loadBalancers/backendAddressPools', loadBalancerName, 'BackendPool')
            }
          ]
          probe: {
            id: resourceId('Microsoft.Network/loadBalancers/probes', loadBalancerName, 'HealthProbe')
          }
        }
      }
    ]
    probes: [
      {
        name: 'HealthProbe'
        id: resourceId('Microsoft.Network/loadBalancers/probes', loadBalancerName, 'HealthProbe')
        properties: {
          protocol: 'Tcp'
          port: 8080
          intervalInSeconds: 5
          numberOfProbes: 1
          probeThreshold: 1
        }
      }
    ]
    inboundNatRules: []
    outboundRules: []
    inboundNatPools: []
  }
  dependsOn: [
    virtualNetwork
  ]
}

Dose anyone knows how to add Backend Pool using Bicep?

2

Answers


  1. Chosen as BEST ANSWER

    I found a video on creating an ARM template he went through creating a VM in Azure Portal and at the very end instead of creating the VM he click on a Hyperlink at the bottom of the page “Download a template for automation” which allows you to download a JSON file. Then I decompile it and made some modifications and then I was able to create the Load Balancer with a Backend Pool.


  2. Firstly, thanks for the info provided by @Vlad DX

    • I tried according to the requirement using MS doc

    how to add Backend Pool using Bicep?

    Using this code, I tried to add the backend pool to the existing load balancer.

    resource loadBalancer 'Microsoft.Network/loadBalancers@2021-02-01' = {
      name: 'myLoadBalancer'
      location: 'eastus'
      sku: {
        name: 'Standard'
      }
      properties: {
        frontendIPConfigurations: [
          {
            name: 'myFrontendIP'
            properties: {
              subnet: {
                id: '/subscriptions/<subscription-id>/resourceGroups/<rg-name>/providers/Microsoft.Network/virtualNetworks/<vnet-name>/subnets/<subnet-name>'
              }
            }
          }
        ]
        backendAddressPools: [
          {
            name: 'myBackendPool'
            properties: {
              backendAddresses: [
                {
                  ipAddress: '10.0.0.10'
                },
                {
                  ipAddress: '10.0.0.11'
                }
              ]
            }
          }
        ]
        loadBalancingRules: []
        probes: []
        inboundNatRules: []
      }
    }
    

    enter image description here

    I can able to see the created VNet.
    enter image description here

    And also, Health probes.
    enter image description here

    Health probes adds or removes the VM’s from the load balancer based upon the response to the health checks.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search