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

Commit

Permalink
feat(module/gwlb): Add variable to manage stickiness type for target …
Browse files Browse the repository at this point in the history
…group (#317)
  • Loading branch information
sebastianczech authored Jun 22, 2023
1 parent 4ebb6dc commit 34374ce
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/gwlb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ No modules.
| <a name="input_lb_tags"></a> [lb\_tags](#input\_lb\_tags) | Map of AWS tags to apply to the created Load Balancer object. These tags are applied after the `global_tags`. | `map(string)` | `{}` | no |
| <a name="input_lb_target_group_tags"></a> [lb\_target\_group\_tags](#input\_lb\_target\_group\_tags) | Map of AWS tags to apply to the created GWLB Target Group. These tags are applied after the `global_tags`. | `map(string)` | `{}` | no |
| <a name="input_name"></a> [name](#input\_name) | Name of the created GWLB and its Target Group. Must be unique per AWS region per AWS account. | `string` | n/a | yes |
| <a name="input_stickiness_type"></a> [stickiness\_type](#input\_stickiness\_type) | If `stickiness_type` is `null`, then attribute `enabled` is set to `false` in stickiness configuration block,<br>value provided in `type` is ignored and by default the Gateway Load Balancer uses 5-tuple to maintain flow stickiness to a specific target appliance.<br>If `stickiness_type` is not `null`, then attribute `enabled` is set to `true` in stickiness configuration block<br>and the stickiness `type` can be then customized by using value:<br>- `source_ip_dest_ip_proto` for 3-tuple (Source IP, Destination IP and Transport Protocol)<br>- `source_ip_dest_ip` for 2-tuple (Source IP and Destination IP)<pre></pre> | `string` | `null` | no |
| <a name="input_subnets"></a> [subnets](#input\_subnets) | Map of subnets where to create the GWLB. Each map's key is the availability zone name and each map's object has an attribute<br>`id` identifying AWS subnet.<br>Example for users of module `subnet_set`:<pre>subnets = module.subnet_set.subnets</pre>Example:<pre>subnets = {<br> "us-east-1a" = { id = "snet-123007" }<br> "us-east-1b" = { id = "snet-123008" }<br>}</pre> | <pre>map(object({<br> id = string<br> }))</pre> | n/a | yes |
| <a name="input_target_instances"></a> [target\_instances](#input\_target\_instances) | Map of instances to attach to the GWLB Target Group. | <pre>map(object({<br> id = string<br> }))</pre> | `{}` | no |
| <a name="input_unhealthy_threshold"></a> [unhealthy\_threshold](#input\_unhealthy\_threshold) | The number of failed health checks required before a healthy target becomes unhealthy. Minimum 2 and maximum 10. | `number` | `3` | no |
Expand Down
5 changes: 5 additions & 0 deletions modules/gwlb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ resource "aws_lb_target_group" "this" {
healthy_threshold = var.healthy_threshold
unhealthy_threshold = var.unhealthy_threshold
}

stickiness {
enabled = var.stickiness_type != null
type = coalesce(var.stickiness_type, "source_ip_dest_ip_proto")
}
}

# Attach one or more Targets (EC2 Instances).
Expand Down
19 changes: 19 additions & 0 deletions modules/gwlb/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@ variable "unhealthy_threshold" {
type = number
}

variable "stickiness_type" {
description = <<-EOF
If `stickiness_type` is `null`, then attribute `enabled` is set to `false` in stickiness configuration block,
value provided in `type` is ignored and by default the Gateway Load Balancer uses 5-tuple to maintain flow stickiness to a specific target appliance.
If `stickiness_type` is not `null`, then attribute `enabled` is set to `true` in stickiness configuration block
and the stickiness `type` can be then customized by using value:
- `source_ip_dest_ip_proto` for 3-tuple (Source IP, Destination IP and Transport Protocol)
- `source_ip_dest_ip` for 2-tuple (Source IP and Destination IP)
```
EOF
default = null
type = string

validation {
condition = (var.stickiness_type == null || contains(["source_ip_dest_ip", "source_ip_dest_ip_proto"], coalesce(var.stickiness_type, "source_ip_dest_ip_proto")))
error_message = "The stickiness_type value must be `null`, `source_ip_dest_ip` or `source_ip_dest_ip_proto`."
}
}

##### Various categories of Tags #####

variable "lb_tags" {
Expand Down

0 comments on commit 34374ce

Please sign in to comment.