Skip to content

Commit

Permalink
feat: add load_balancing_anomaly_mitigation to TG
Browse files Browse the repository at this point in the history
  • Loading branch information
mschfh committed Nov 25, 2024
1 parent ef2c73b commit db4689c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ Available targets:
| <a name="input_load_balancer_name"></a> [load\_balancer\_name](#input\_load\_balancer\_name) | The name for the default load balancer, uses a module label name if left empty | `string` | `""` | no |
| <a name="input_load_balancer_name_max_length"></a> [load\_balancer\_name\_max\_length](#input\_load\_balancer\_name\_max\_length) | The max length of characters for the load balancer. | `number` | `32` | no |
| <a name="input_load_balancing_algorithm_type"></a> [load\_balancing\_algorithm\_type](#input\_load\_balancing\_algorithm\_type) | Determines how the load balancer selects targets when routing requests. Only applicable for Application Load Balancer Target Groups | `string` | `"round_robin"` | no |
| <a name="input_load_balancing_anomaly_mitigation"></a> [load\_balancing\_anomaly\_mitigation](#input\_load\_balancing\_anomaly\_mitigation) | Determines whether to enable target anomaly mitigation. Only supported by the weighted\_random load balancing algorithm type. Valid values are 'on' or 'off'. | `string` | `"off"` | no |
| <a name="input_name"></a> [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.<br/>This is the only ID element not also included as a `tag`.<br/>The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no |
| <a name="input_noncurrent_version_expiration_days"></a> [noncurrent\_version\_expiration\_days](#input\_noncurrent\_version\_expiration\_days) | (Deprecated, use `lifecycle_configuration_rules` instead)<br/>Specifies when non-current object versions expire (in days) | `number` | `90` | no |
Expand Down
1 change: 1 addition & 0 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
| <a name="input_load_balancer_name"></a> [load\_balancer\_name](#input\_load\_balancer\_name) | The name for the default load balancer, uses a module label name if left empty | `string` | `""` | no |
| <a name="input_load_balancer_name_max_length"></a> [load\_balancer\_name\_max\_length](#input\_load\_balancer\_name\_max\_length) | The max length of characters for the load balancer. | `number` | `32` | no |
| <a name="input_load_balancing_algorithm_type"></a> [load\_balancing\_algorithm\_type](#input\_load\_balancing\_algorithm\_type) | Determines how the load balancer selects targets when routing requests. Only applicable for Application Load Balancer Target Groups | `string` | `"round_robin"` | no |
| <a name="input_load_balancing_anomaly_mitigation"></a> [load\_balancing\_anomaly\_mitigation](#input\_load\_balancing\_anomaly\_mitigation) | Determines whether to enable target anomaly mitigation. Only supported by the weighted\_random load balancing algorithm type. Valid values are 'on' or 'off'. | `string` | `"off"` | no |
| <a name="input_name"></a> [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.<br/>This is the only ID element not also included as a `tag`.<br/>The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no |
| <a name="input_noncurrent_version_expiration_days"></a> [noncurrent\_version\_expiration\_days](#input\_noncurrent\_version\_expiration\_days) | (Deprecated, use `lifecycle_configuration_rules` instead)<br/>Specifies when non-current object versions expire (in days) | `number` | `90` | no |
Expand Down
21 changes: 11 additions & 10 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,17 @@ module "default_target_group_label" {
}

resource "aws_lb_target_group" "default" {
count = module.this.enabled && var.default_target_group_enabled ? 1 : 0
name = var.target_group_name == "" ? module.default_target_group_label.id : substr(var.target_group_name, 0, var.target_group_name_max_length)
port = var.target_group_port
protocol = var.target_group_protocol
protocol_version = var.target_group_protocol_version
vpc_id = var.vpc_id
target_type = var.target_group_target_type
load_balancing_algorithm_type = var.load_balancing_algorithm_type
deregistration_delay = var.deregistration_delay
slow_start = var.slow_start
count = module.this.enabled && var.default_target_group_enabled ? 1 : 0
name = var.target_group_name == "" ? module.default_target_group_label.id : substr(var.target_group_name, 0, var.target_group_name_max_length)
port = var.target_group_port
protocol = var.target_group_protocol
protocol_version = var.target_group_protocol_version
vpc_id = var.vpc_id
target_type = var.target_group_target_type
load_balancing_algorithm_type = var.load_balancing_algorithm_type
load_balancing_anomaly_mitigation = var.load_balancing_anomaly_mitigation
deregistration_delay = var.deregistration_delay
slow_start = var.slow_start

health_check {
protocol = var.health_check_protocol != null ? var.health_check_protocol : var.target_group_protocol
Expand Down
19 changes: 19 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,25 @@ variable "load_balancing_algorithm_type" {
description = "Determines how the load balancer selects targets when routing requests. Only applicable for Application Load Balancer Target Groups"
}

variable "load_balancing_anomaly_mitigation" {
type = string
default = "off"
description = "Determines whether to enable target anomaly mitigation. Only supported by the weighted_random load balancing algorithm type. Valid values are 'on' or 'off'."

validation {
condition = contains(["on", "off"], var.load_balancing_anomaly_mitigation)
error_message = "load_balancing_anomaly_mitigation must be either 'on' or 'off'"
}

# TODO: Uncomment improved validation block once Terraform version is upgraded to >= 1.9
# validation {
# condition = var.load_balancing_anomaly_mitigation == "off" || (
# var.load_balancing_anomaly_mitigation == "on" && var.load_balancing_algorithm_type == "weighted_random"
# )
# error_message = "load_balancing_anomaly_mitigation can only be 'on' when load_balancing_algorithm_type is 'weighted_random'"
# }
}

variable "default_target_group_enabled" {
type = bool
description = "Whether the default target group should be created or not."
Expand Down

0 comments on commit db4689c

Please sign in to comment.