Azure Load Balancer Rule

This page shows how to write Terraform and Azure Resource Manager for Load Balancer Rule and write them securely.

azurerm_lb_rule (Terraform)

The Rule in Load Balancer can be configured in Terraform with the resource name azurerm_lb_rule. The following sections describe 4 examples of how to use the resource and its parameters.

Example Usage from GitHub

lb_rules.tf#L1
resource "azurerm_lb_rule" "http" {
  resource_group_name            = var.resource_group_name
  loadbalancer_id                = azurerm_lb.pcarey-tfe-lb.id
  name                           = "httpRule"
  protocol                       = "Tcp"
  frontend_port                  = 80
clients_lb.tf#L35
resource "azurerm_lb_rule" "clients_nomad" {
  name                           = "clients-nomad-lb-rule"
  resource_group_name            = azurerm_resource_group.hashistack.name
  loadbalancer_id                = azurerm_lb.clients.id
  backend_address_pool_id        = azurerm_lb_backend_address_pool.clients_lb.id
  probe_id                       = azurerm_lb_probe.clients_nomad.id
clients_lb.tf#L33
resource "azurerm_lb_rule" "clients_nomad" {
  name                           = "clients-nomad-lb-rule"
  resource_group_name            = azurerm_resource_group.hashistack.name
  loadbalancer_id                = azurerm_lb.clients.id
  backend_address_pool_id        = azurerm_lb_backend_address_pool.clients_lb.id
  probe_id                       = azurerm_lb_probe.clients_nomad.id
network-lb.tf#L31
resource "azurerm_lb_rule" "load_balancer_ssh_rule" {
  resource_group_name            = azurerm_resource_group.main.name
  loadbalancer_id                = azurerm_lb.lb-rancher.id
  name                           = "SSHRule"
  protocol                       = "Tcp"
  frontend_port                  = 22

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Manages a Load Balancer Rule.

NOTE When using this resource, the Load Balancer needs to have a FrontEnd IP Configuration Attached

Microsoft.Network/loadBalancers (Azure Resource Manager)

The loadBalancers in Microsoft.Network can be configured in Azure Resource Manager with the resource name Microsoft.Network/loadBalancers. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

DiagnosticSettingsFilterTest.test_filter_diagnostic_settings_enabled.json#L37
                                "type": "Microsoft.Network/loadBalancers",
                                "location": "southcentralus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "f62dd440-2673-4f36-8e59-fcbdeb4a5959",
                                    "frontendIPConfigurations": [
LoadBalancerTest.test_find_by_name.json#L37
                                "type": "Microsoft.Network/loadBalancers",
                                "location": "southcentralus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "f62dd440-2673-4f36-8e59-fcbdeb4a5959",
                                    "frontendIPConfigurations": [
LoadBalancerTest.test_find_by_name.json#L37
                                "type": "Microsoft.Network/loadBalancers",
                                "location": "southcentralus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "f62dd440-2673-4f36-8e59-fcbdeb4a5959",
                                    "frontendIPConfigurations": [
DiagnosticSettingsFilterTest.test_filter_diagnostic_settings_enabled.json#L37
                                "type": "Microsoft.Network/loadBalancers",
                                "location": "southcentralus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "f62dd440-2673-4f36-8e59-fcbdeb4a5959",
                                    "frontendIPConfigurations": [
LoadBalancerTest.test_find_by_name.json#L37
                                "type": "Microsoft.Network/loadBalancers",
                                "location": "southcentralus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "f62dd440-2673-4f36-8e59-fcbdeb4a5959",
                                    "frontendIPConfigurations": [
LoadBalancerTest.test_find_by_name.json#L37
                                "type": "Microsoft.Network/loadBalancers",
                                "location": "southcentralus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "f62dd440-2673-4f36-8e59-fcbdeb4a5959",
                                    "frontendIPConfigurations": [
DiagnosticSettingsFilterTest.test_filter_diagnostic_settings_enabled.json#L37
                                "type": "Microsoft.Network/loadBalancers",
                                "location": "southcentralus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "f62dd440-2673-4f36-8e59-fcbdeb4a5959",
                                    "frontendIPConfigurations": [
LoadBalancerTest.test_find_by_name.json#L37
                                "type": "Microsoft.Network/loadBalancers",
                                "location": "southcentralus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "f62dd440-2673-4f36-8e59-fcbdeb4a5959",
                                    "frontendIPConfigurations": [
DiagnosticSettingsFilterTest.test_filter_diagnostic_settings_enabled.json#L37
                                "type": "Microsoft.Network/loadBalancers",
                                "location": "southcentralus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "f62dd440-2673-4f36-8e59-fcbdeb4a5959",
                                    "frontendIPConfigurations": [
LoadBalancerTest.test_find_by_name.json#L37
                                "type": "Microsoft.Network/loadBalancers",
                                "location": "southcentralus",
                                "properties": {
                                    "provisioningState": "Succeeded",
                                    "resourceGuid": "f62dd440-2673-4f36-8e59-fcbdeb4a5959",
                                    "frontendIPConfigurations": [

Parameters

  • name required - string
  • type required - string
  • apiVersion required - string
  • location required - string

    Resource location.

  • tags optional - string

    Resource tags.

  • extendedLocation optional
      • name required - string

        The name of the extended location.

      • type required - string

        The type of the extended location.

  • sku optional
      • name optional - string

        Name of a load balancer SKU.

      • tier optional - string

        Tier of a load balancer SKU.

  • properties required
      • frontendIPConfigurations optional array
          • properties optional
              • privateIPAddress optional - string

                The private IP address of the IP configuration.

              • privateIPAllocationMethod optional - string

                The Private IP allocation method.

              • privateIPAddressVersion optional - string

                Whether the specific ipconfiguration is IPv4 or IPv6. Default is taken as IPv4.

              • subnet optional
                  • id required - string

                    Resource ID.

              • publicIPAddress optional
                  • id required - string

                    Resource ID.

              • publicIPPrefix optional
                  • id required - string

                    Resource ID.

          • name required - string

            The name of the resource that is unique within the set of frontend IP configurations used by the load balancer. This name can be used to access the resource.

          • zones optional - array

            A list of availability zones denoting the IP allocated for the resource needs to come from.

      • backendAddressPools optional array
          • properties optional
              • location optional - string

                The location of the backend address pool.

              • loadBalancerBackendAddresses optional array
                  • properties optional
                      • virtualNetwork optional
                          • id required - string

                            Resource ID.

                      • subnet optional
                          • id required - string

                            Resource ID.

                      • ipAddress optional - string

                        IP Address belonging to the referenced virtual network.

                      • loadBalancerFrontendIPConfiguration optional
                          • id required - string

                            Resource ID.

                  • name optional - string

                    Name of the backend address.

          • name required - string

            The name of the resource that is unique within the set of backend address pools used by the load balancer. This name can be used to access the resource.

      • loadBalancingRules optional array
          • properties optional
              • frontendIPConfiguration required
                  • id required - string

                    Resource ID.

              • backendAddressPool optional
                  • id required - string

                    Resource ID.

              • probe optional
                  • id required - string

                    Resource ID.

              • protocol required - string

                The reference to the transport protocol used by the load balancing rule.

              • loadDistribution optional - string

                The load distribution policy for this rule.

              • frontendPort required - integer

                The port for the external endpoint. Port numbers for each rule must be unique within the Load Balancer. Acceptable values are between 0 and 65534. Note that value 0 enables "Any Port".

              • backendPort required - integer

                The port used for internal connections on the endpoint. Acceptable values are between 0 and 65535. Note that value 0 enables "Any Port".

              • idleTimeoutInMinutes optional - integer

                The timeout for the TCP idle connection. The value can be set between 4 and 30 minutes. The default value is 4 minutes. This element is only used when the protocol is set to TCP.

              • enableFloatingIP optional - boolean

                Configures a virtual machine's endpoint for the floating IP capability required to configure a SQL AlwaysOn Availability Group. This setting is required when using the SQL AlwaysOn Availability Groups in SQL server. This setting can't be changed after you create the endpoint.

              • enableTcpReset optional - boolean

                Receive bidirectional TCP Reset on TCP flow idle timeout or unexpected connection termination. This element is only used when the protocol is set to TCP.

              • disableOutboundSnat optional - boolean

                Configures SNAT for the VMs in the backend pool to use the publicIP address specified in the frontend of the load balancing rule.

          • name required - string

            The name of the resource that is unique within the set of load balancing rules used by the load balancer. This name can be used to access the resource.

      • probes optional array
          • properties optional
              • protocol required - string

                The protocol of the end point. If 'Tcp' is specified, a received ACK is required for the probe to be successful. If 'Http' or 'Https' is specified, a 200 OK response from the specifies URI is required for the probe to be successful.

              • port required - integer

                The port for communicating the probe. Possible values range from 1 to 65535, inclusive.

              • intervalInSeconds optional - integer

                The interval, in seconds, for how frequently to probe the endpoint for health status. Typically, the interval is slightly less than half the allocated timeout period (in seconds) which allows two full probes before taking the instance out of rotation. The default value is 15, the minimum value is 5.

              • numberOfProbes required - integer

                The number of probes where if no response, will result in stopping further traffic from being delivered to the endpoint. This values allows endpoints to be taken out of rotation faster or slower than the typical times used in Azure.

              • requestPath optional - string

                The URI used for requesting health status from the VM. Path is required if a protocol is set to http. Otherwise, it is not allowed. There is no default value.

          • name required - string

            The name of the resource that is unique within the set of probes used by the load balancer. This name can be used to access the resource.

      • inboundNatRules optional array
          • properties optional
              • frontendIPConfiguration required
                  • id required - string

                    Resource ID.

              • protocol required - string

                The reference to the transport protocol used by the load balancing rule.

              • frontendPort required - integer

                The port for the external endpoint. Port numbers for each rule must be unique within the Load Balancer. Acceptable values range from 1 to 65534.

              • backendPort required - integer

                The port used for the internal endpoint. Acceptable values range from 1 to 65535.

              • idleTimeoutInMinutes optional - integer

                The timeout for the TCP idle connection. The value can be set between 4 and 30 minutes. The default value is 4 minutes. This element is only used when the protocol is set to TCP.

              • enableFloatingIP optional - boolean

                Configures a virtual machine's endpoint for the floating IP capability required to configure a SQL AlwaysOn Availability Group. This setting is required when using the SQL AlwaysOn Availability Groups in SQL server. This setting can't be changed after you create the endpoint.

              • enableTcpReset optional - boolean

                Receive bidirectional TCP Reset on TCP flow idle timeout or unexpected connection termination. This element is only used when the protocol is set to TCP.

          • name required - string

            The name of the resource that is unique within the set of inbound NAT rules used by the load balancer. This name can be used to access the resource.

      • inboundNatPools optional array
          • properties optional
              • frontendIPConfiguration required
                  • id required - string

                    Resource ID.

              • protocol required - string

                The reference to the transport protocol used by the inbound NAT pool.

              • frontendPortRangeStart required - integer

                The first port number in the range of external ports that will be used to provide Inbound Nat to NICs associated with a load balancer. Acceptable values range between 1 and 65534.

              • frontendPortRangeEnd required - integer

                The last port number in the range of external ports that will be used to provide Inbound Nat to NICs associated with a load balancer. Acceptable values range between 1 and 65535.

              • backendPort required - integer

                The port used for internal connections on the endpoint. Acceptable values are between 1 and 65535.

              • idleTimeoutInMinutes optional - integer

                The timeout for the TCP idle connection. The value can be set between 4 and 30 minutes. The default value is 4 minutes. This element is only used when the protocol is set to TCP.

              • enableFloatingIP optional - boolean

                Configures a virtual machine's endpoint for the floating IP capability required to configure a SQL AlwaysOn Availability Group. This setting is required when using the SQL AlwaysOn Availability Groups in SQL server. This setting can't be changed after you create the endpoint.

              • enableTcpReset optional - boolean

                Receive bidirectional TCP Reset on TCP flow idle timeout or unexpected connection termination. This element is only used when the protocol is set to TCP.

          • name required - string

            The name of the resource that is unique within the set of inbound NAT pools used by the load balancer. This name can be used to access the resource.

      • outboundRules optional array
          • properties optional
              • allocatedOutboundPorts optional - integer

                The number of outbound ports to be used for NAT.

              • frontendIPConfigurations required array
                  • id required - string

                    Resource ID.

              • backendAddressPool required
                  • id required - string

                    Resource ID.

              • protocol required - string

                The protocol for the outbound rule in load balancer.

              • enableTcpReset optional - boolean

                Receive bidirectional TCP Reset on TCP flow idle timeout or unexpected connection termination. This element is only used when the protocol is set to TCP.

              • idleTimeoutInMinutes optional - integer

                The timeout for the TCP idle connection.

          • name optional - string

            The name of the resource that is unique within the set of outbound rules used by the load balancer. This name can be used to access the resource.

Frequently asked questions

What is Azure Load Balancer Rule?

Azure Load Balancer Rule is a resource for Load Balancer of Microsoft Azure. Settings can be wrote in Terraform.

Where can I find the example code for the Azure Load Balancer Rule?

For Terraform, the pcareyrh/tfe_deploy, nehrman/terraform-nomad-multicloud and louievandyke/autoscaler-demos source code examples are useful. See the Terraform Example section for further details.

For Azure Resource Manager, the LRuttenCN/cloud-custodian, LRuttenCN/cloud-custodian and harsh4870/cloud-custodian source code examples are useful. See the Azure Resource Manager Example section for further details.