diff --git a/README.md b/README.md index 7a69097..bec656a 100644 --- a/README.md +++ b/README.md @@ -261,6 +261,7 @@ Available targets: | [load\_balancer\_name](#input\_load\_balancer\_name) | The name for the default load balancer, uses a module label name if left empty | `string` | `""` | no | | [load\_balancer\_name\_max\_length](#input\_load\_balancer\_name\_max\_length) | The max length of characters for the load balancer. | `number` | `32` | no | | [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 | +| [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 | | [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a `tag`.
The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no | | [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 | | [noncurrent\_version\_expiration\_days](#input\_noncurrent\_version\_expiration\_days) | (Deprecated, use `lifecycle_configuration_rules` instead)
Specifies when non-current object versions expire (in days) | `number` | `90` | no | diff --git a/docs/terraform.md b/docs/terraform.md index 3e8b1d1..9f7f99e 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -99,6 +99,7 @@ | [load\_balancer\_name](#input\_load\_balancer\_name) | The name for the default load balancer, uses a module label name if left empty | `string` | `""` | no | | [load\_balancer\_name\_max\_length](#input\_load\_balancer\_name\_max\_length) | The max length of characters for the load balancer. | `number` | `32` | no | | [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 | +| [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 | | [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a `tag`.
The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no | | [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 | | [noncurrent\_version\_expiration\_days](#input\_noncurrent\_version\_expiration\_days) | (Deprecated, use `lifecycle_configuration_rules` instead)
Specifies when non-current object versions expire (in days) | `number` | `90` | no | diff --git a/main.tf b/main.tf index 4487705..856b5e5 100644 --- a/main.tf +++ b/main.tf @@ -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 diff --git a/variables.tf b/variables.tf index d6171fd..19892ba 100644 --- a/variables.tf +++ b/variables.tf @@ -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."