Resource: aws_lb_target_group#
Manages a target group. For details about target groups, see the user documentation.
Example Usage#
resource "aws_vpc" "example" {
cidr_block = "10.1.0.0/16"
tags = {
Name = "tf-vpc"
}
}
resource "aws_lb_target_group" "example" {
name = "tf-lb-tg"
target_type = "instance"
port = 80
protocol = "HTTP"
vpc_id = aws_vpc.example.id
tags = {
Name = "tf-lb-tg"
}
}
Argument Reference#
The following arguments are supported:
port- (Required) The port on which targets will receive requests. Can be overridden when registering a specific target.- Valid values: From 1 to 65535
protocol- (Required) The protocol that will be used for routing traffic to the targets.- Valid values:
TCP,UDP,HTTP
- Valid values:
vpc_id- (Required) The ID of the VPC.health_check- (Optional, Editable) The health check configuration. The structure of this block is described below.name- (Optional) The name of the target group.- Value length: From 1 to 32 symbols
- Constraints:
namecannot be specified ifname_prefixis set- The value can contain only Latin letters, numbers, and hyphens (
-) - The value must start and end with a Latin letter or number
name_prefix- (Optional) Creates a unique name beginning with the specified prefix.- Value length: From 1 to 6 symbols
- Constraints:
name_prefixcannot be specified ifnameis set- The value constraints are the same as for
name
-> Note If name and name_prefix are not specified, Terraform will autogenerate a name with the prefix tf-.
protocol_version- (Optional) The version of the protocol (only for HTTP).- Valid values:
HTTP1,HTTP2
- Valid values:
tags- (Optional, Editable) Map of tags to assign to the target group. If a providerdefault_tagsconfiguration block is used, tags with matching keys will overwrite those defined at the provider level.target_type- (Optional) The type of the target. All targets in a target group must have the same type.- Valid values:
instance - Default value:
instance
- Valid values:
health_check#
The health_check block has the following structure:
enabled- (Optional, Editable) Indicates whether health check will be enabled.- Default value:
true - Constraints: Health check must be enabled for target groups with instance target type
- Default value:
healthy_threshold- (Optional, Editable) Number of consecutive successful health checks after which the target status changes to healthy.- Valid values: From 2 to 10
- Constraints: For TCP and UDP target groups,
healthy_thresholdandunhealthy_thresholdmust be the same
interval- (Optional, Editable) The amount of time, in seconds, between health checks on an individual target.- Valid values: From 5 to 300
- Default value: 30
port- (Optional, Editable) The port used to perform health checks on targets. If value istraffic-port, the port, on which the target receives requests, is used for health checks.- Valid values:
traffic-port - Default value:
traffic-port
- Valid values:
protocol- (Optional, Editable) The protocol used to perform health checks on targets.- Valid values:
TCP,UDP,HTTP - Constraints:
health_check.protocoland target groupprotocolmust be the same
- Valid values:
timeout- (Optional, Editable) The amount of time, in seconds, after which no response indicates a failed health check.- Valid values: From 2 to 120
- Constraints: You can set a custom timeout value for HTTP target groups only
unhealthy_threshold- (Optional, Editable) Number of consecutive failed health checks after which the target status changes to unhealthy.- Valid values: From 2 to 10
- Constraints: For TCP and UDP target groups,
healthy_thresholdandunhealthy_thresholdmust be the same
Attribute Reference#
Supported attributes#
In addition to all arguments above, the following attributes are exported:
arn- The Amazon Resource Name (ARN) of the target group.health_check- The health check configuration. Exported attributes for the block are described below.id- The ARN of the target group.tags_all- Map of tags assigned to the target group, including those inherited from the providerdefault_tagsconfiguration block.
health_check attributes#
In addition to health_check arguments above, the following attributes are exported:
matcher- The HTTP code used to check the target availability.path- The destination for the health check request.
Unsupported attributes#
~> Note These attributes may be present in the terraform.tfstate file, but they have preset values and cannot be specified in configuration files.
The following attributes are not currently supported:
arn_suffix, connection_termination, deregistration_delay, lambda_multi_value_headers_enabled, load_balancing_algorithm_type, preserve_client_ip, proxy_protocol_v2, slow_start, stickiness.
Import#
The target group can be imported using arn, e.g.,
$ terraform import aws_lb_target_group.example arn:c2:elasticloadbalancing::project-name@customer-name:targetgroup/tg-12345678