Skip to content

Load Balancer

See below for an example of a load balancer configuration. Tags are used to identify the resources that will be added to the load balancer's backend address pool.

Load Balancer Variables Example

load_balancer = {
    PKIaaS-LB = {
        resource_group = "PKIaaS_Ansible"
        sku = "Standard"

        frontend_ip_configuration = {
            pkiaas_fe_ip = {
                public_ip_address = "pkiaas_public_ip"
            }
        }

        rules = {
            route-443-8443 = {
                frontend_port = 443
                backend_port = 8443
                probe = "HTTP"
                frontend_ip_configuration_name = "pkiaas_fe_ip"
                backend_address_pools = ["pkiaas-backend"]
            },
            route-4433-4433 = {
                frontend_port = 4433
                backend_port = 4433
                probe = "HTTP"
                frontend_ip_configuration_name = "pkiaas_fe_ip"
                backend_address_pools = ["pkiaas-backend"]
            },
            route-80-8080 = {
                frontend_port = 80
                backend_port = 8080
                probe = "HTTP"
                frontend_ip_configuration_name = "pkiaas_fe_ip"
                backend_address_pools = ["pkiaas-backend"]
            },
            route-dns = {
                frontend_port = 53
                backend_port = 55
                protocol = "Udp"
                probe = "HTTP"
                frontend_ip_configuration_name = "pkiaas_fe_ip"
                backend_address_pools = ["pkiaas-backend"]
            }
        }

        probes = {
            HTTP = {
                protocol = "Https"
                port = 8443
                request_path = "/"
            },
            SSH = {
                Protocol = "Tcp"
                port = 22
            }
        }

        nat_rules = {
            ssh = {
                frontend_port_start = 22
                frontend_port_end = 22
                backend_port = 22
                backend_address_pool = "pkiaasdockera"
                frontend_ip_configuration_name = "pkiaas_fe_ip"
            },
            prometheus_a = {
                frontend_port_start = 9100
                frontend_port_end = 9100
                backend_port = 9100
                backend_address_pool = "pkiaasdockera"
                frontend_ip_configuration_name = "pkiaas_fe_ip"
            },
            prometheus_b = {
                frontend_port_start = 9101
                frontend_port_end = 9101
                backend_port = 9100
                backend_address_pool = "pkiaasdockerb"
                frontend_ip_configuration_name = "pkiaas_fe_ip"
            }
        }

        outbound_rules = {
            internet-only = {
                backend_address_pool = "internet-only"
                frontend_ip_configuration = [
                    {
                        name = "pkiaas_fe_ip"
                    }
                ]
            }
        }

        backend_address_pool = {
            internet-only = {
                target = {
                    vm_tag = {
                        key = "internet-only-backend"
                        value = "true"
                    }
                }
            },
            pkiaas-backend = {
                target = {
                    vm_tag = {
                        key = "pkiaas-backend"
                        value = "true"
                    }
                }
            },
            pkiaasdockera = {
                target = {
                    vm_tag = {
                        key = "pkiaasdockera-backend"
                        value = "true"
                    }
                }
            },
            pkiaasdockerb = {
                target = {
                    vm_tag = {
                        key = "pkiaasdockerb-backend"
                        value = "true"
                    }
                }
            }
        }
    }
}

VM Tags Example

linux_vms = {
    pkiaasdockera = {
        names = [
            "pkiaasdockera"
        ]
        size = "Standard_B1ms"
        resource_group = "PKIaaS_Ansible"
        nics = {
            primary = {
                accelerated_networking_enabled = false
                ip_configuration = [{
                    subnet = "PKIaaS.app"
                }]
            }
        }
        source_image_reference = {
            publisher = "canonical"
            offer = "ubuntu-24_04-lts"
            sku = "server"
            version = "latest"
        }
        tags = {
            internet-only-backend = "true"
            pkiaasdockera-backend = "true"
            pkiaas-backend = "true"
        }
    }
    pkiaasdockerb = {
        names = [
            "pkiaasdockera"
        ]
        size = "Standard_B1ms"
        resource_group = "PKIaaS_Ansible"
        nics = {
            primary = {
                accelerated_networking_enabled = false
                ip_configuration = [{
                    subnet = "PKIaaS.app"
                }]
            }
        }
        source_image_reference = {
            publisher = "canonical"
            offer = "ubuntu-24_04-lts"
            sku = "server"
            version = "latest"
        }
        tags = {
            internet-only-backend = "true"
            pkiaasdockerb-backend = "true"
            pkiaas-backend = "true"
        }
    }
}

Load Balancer Variable Reference

The following fields are set directly on each load_balancer object.

Field Type Description Default
sku string The SKU of the azurerm_lb. One of Basic, Standard, or Gateway. Standard is required for private/internal frontends and for outbound rules. "Standard"

Private DNS A Record for a Frontend

A private DNS A record can resolve to a load balancer frontend's private IP by referencing the load balancer key and the frontend name (the frontend entry's name, or its map key when name is not set). The IP is read at apply time, so Dynamic allocation works. See Private DNS A Record for the full variable reference.

private_dns_a_record = {
    intranet = {
        resource_group = "network"
        zone = "sapphirehealth"
        load_balancer = {
            key = "PKIaaS-LB"
            frontend_ip_configuration = "pkiaas_fe_ip"
        }
    }
}

Notes

Note: The sku field maps directly to the azurerm_lb SKU. Earlier the module emitted no sku, which made Azure default the load balancer to Basic; entries now default to Standard. Set sku = "Standard" (or omit it to take the default) for internal load balancers and any configuration that uses outbound_rules.

Changelog

  • The rules and outbound_rules resources now use the current azurerm argument names floating_ip_enabled (on azurerm_lb_rule) and tcp_reset_enabled (on azurerm_lb_outbound_rule), replacing the deprecated enable_floating_ip / enable_tcp_reset provider arguments. The tfvars-facing keys are renamed to match: set floating_ip_enabled on a rule and tcp_reset_enabled on an outbound rule (previously enable_floating_ip / enable_tcp_reset). No environment currently provisions a load balancer through this module, so no tfvars require updating.