Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
feat(module/loadbalancer): add session persitance to the available op…
Browse files Browse the repository at this point in the history
…tions (#195)
  • Loading branch information
FoSix authored Sep 30, 2022
1 parent 429af2f commit 26febe6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/loadbalancer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ No modules.
| <a name="input_avzones"></a> [avzones](#input\_avzones) | After provider version 3.x you need to specify in which availability zone(s) you want to place IP.<br>ie: for zone-redundant with 3 availability zone in current region value will be:<pre>["1","2","3"]</pre> | `list(string)` | `[]` | no |
| <a name="input_backend_name"></a> [backend\_name](#input\_backend\_name) | The name of the backend pool to create. If an empty name is provided, it will be auto-generated.<br>All the frontends of the load balancer always use the same single backend. | `string` | `""` | no |
| <a name="input_enable_zones"></a> [enable\_zones](#input\_enable\_zones) | If false, all the subnet-associated frontends and also all created Public IP addresses default to not to use Availability Zones (the `No-Zone` setting). It is intended for the regions that do not yet support Availability Zones. | `bool` | `true` | no |
| <a name="input_frontend_ips"></a> [frontend\_ips](#input\_frontend\_ips) | A map of objects describing LB frontend IP configurations. Used for both public or private load balancers. <br>Keys of the map are the names of the created load balancers.<br><br>Public LB<br><br>- `create_public_ip` : Optional. Set to `true` to create a public IP.<br>- `public_ip_name` : Ignored if `create_public_ip` is `true`. The existing public IP resource name to use.<br>- `public_ip_resource_group` : Ignored if `create_public_ip` is `true` or if `public_ip_name` is null. The name of the resource group which holds `public_ip_name`.<br><br>Example<pre>frontend_ips = {<br> pip_existing = {<br> create_public_ip = false<br> public_ip_name = "my_ip"<br> public_ip_resource_group = "my_rg_name"<br> rules = {<br> HTTP = {<br> port = 80<br> protocol = "Tcp"<br> }<br> }<br> }<br>}</pre>Private LB<br><br>- `subnet_id` : Identifier of an existing subnet.<br>- `private_ip_address_allocation` : Type of private allocation: `Static` or `Dynamic`.<br>- `private_ip_address` : If `Static`, the private IP address.<br><br>Example<pre>frontend_ips = {<br> internal_fe = {<br> subnet_id = azurerm_subnet.this.id<br> private_ip_address_allocation = "Static"<br> private_ip_address = "192.168.0.10"<br> rules = {<br> HA_PORTS = {<br> port = 0<br> protocol = "All"<br> }<br> }<br> }<br>}</pre>Zone usage<br><br>You can specifies a list of Availability Zones in which the IP Address for this Load Balancer should be located.<br><br>- `zones` : Specify in which zones you want to create frontend IP address. Pass list with zone coverage, ie: `["1","2","3"]`<br><br>Example<pre>frontend_ips = {<br> internal = {<br> subnet_id = azurerm_subnet.this.id<br> private_ip_address_allocation = "Static"<br> private_ip_address = "192.168.0.10"<br> zones = ["1","2","3"]<br> }<br>}</pre> | `any` | n/a | yes |
| <a name="input_frontend_ips"></a> [frontend\_ips](#input\_frontend\_ips) | A map of objects describing LB frontend IP configurations. Used for both public or private load balancers. <br>Keys of the map are the names of the created load balancers.<br><br>Public LB<br><br>- `create_public_ip` : Optional. Set to `true` to create a public IP.<br>- `public_ip_name` : Ignored if `create_public_ip` is `true`. The existing public IP resource name to use.<br>- `public_ip_resource_group` : Ignored if `create_public_ip` is `true` or if `public_ip_name` is null. The name of the resource group which holds `public_ip_name`.<br><br>Example<pre>frontend_ips = {<br> pip_existing = {<br> create_public_ip = false<br> public_ip_name = "my_ip"<br> public_ip_resource_group = "my_rg_name"<br> rules = {<br> HTTP = {<br> port = 80<br> protocol = "Tcp"<br> }<br> }<br> }<br>}</pre>Private LB<br><br>- `subnet_id` : Identifier of an existing subnet.<br>- `private_ip_address_allocation` : Type of private allocation: `Static` or `Dynamic`.<br>- `private_ip_address` : If `Static`, the private IP address.<br><br>Example<pre>frontend_ips = {<br> internal_fe = {<br> subnet_id = azurerm_subnet.this.id<br> private_ip_address_allocation = "Static"<br> private_ip_address = "192.168.0.10"<br> rules = {<br> HA_PORTS = {<br> port = 0<br> protocol = "All"<br> }<br> }<br> }<br>}</pre>Zone usage<br><br>You can specifies a list of Availability Zones in which the IP Address for this Load Balancer should be located.<br><br>- `zones` : Specify in which zones you want to create frontend IP address. Pass list with zone coverage, ie: `["1","2","3"]`<br><br>Example<pre>frontend_ips = {<br> internal = {<br> subnet_id = azurerm_subnet.this.id<br> private_ip_address_allocation = "Static"<br> private_ip_address = "192.168.0.10"<br> zones = ["1","2","3"]<br> }<br>}</pre>Session persistence/Load distribution<br><br>By default the Load Balancer uses a 5 tuple hash to map traffic to available servers. This can be controlled using `session_persistence` property defined inside a role. Available values are:<br><br>- `Default` : this is the 5 tuple hash - this method is also used when no property is defined<br>- `SourceIP` : a 2 tuple hash is used<br>- `SourceIPProtocol` : a 3 tuple hash is used<br><br>Example<pre>frontend_ips = {<br> rule_1 = {<br> create_public_ip = true<br> rules = {<br> HTTP = {<br> port = 80<br> protocol = "Tcp"<br> session_persistence = "SourceIP"<br> }<br> }<br> }<br> }</pre> | `any` | n/a | yes |
| <a name="input_location"></a> [location](#input\_location) | Region to deploy load balancer and dependencies. | `string` | n/a | yes |
| <a name="input_name"></a> [name](#input\_name) | The name of the load balancer. | `string` | n/a | yes |
| <a name="input_network_security_allow_source_ips"></a> [network\_security\_allow\_source\_ips](#input\_network\_security\_allow\_source\_ips) | List of IP CIDR ranges (such as `["192.168.0.0/16"]` or `["*"]`) from which the inbound traffic to all frontends should be allowed.<br>If it's empty, user is responsible for configuring a Network Security Group separately, possibly using the `frontend_combined_rules` output.<br>The list cannot include Azure tags like "Internet" or "Sql.EastUS". | `list(string)` | `[]` | no |
Expand Down
1 change: 1 addition & 0 deletions modules/loadbalancer/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ resource "azurerm_lb_rule" "lb_rules" {
frontend_port = each.value.rule.port
enable_floating_ip = true
disable_outbound_snat = local.disable_outbound_snat
load_distribution = try(each.value.rule.session_persistence, null)
}

resource "azurerm_lb_outbound_rule" "outb_rules" {
Expand Down
25 changes: 25 additions & 0 deletions modules/loadbalancer/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,31 @@ variable "frontend_ips" {
}
}
```
Session persistence/Load distribution
By default the Load Balancer uses a 5 tuple hash to map traffic to available servers. This can be controlled using `session_persistence` property defined inside a role. Available values are:
- `Default` : this is the 5 tuple hash - this method is also used when no property is defined
- `SourceIP` : a 2 tuple hash is used
- `SourceIPProtocol` : a 3 tuple hash is used
Example
```
frontend_ips = {
rule_1 = {
create_public_ip = true
rules = {
HTTP = {
port = 80
protocol = "Tcp"
session_persistence = "SourceIP"
}
}
}
}
```
EOF
}
variable "outbound_rules" {
Expand Down

0 comments on commit 26febe6

Please sign in to comment.