Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load balancer fixes #1884

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 36 additions & 26 deletions aws/resource_aws_lb_target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func resourceAwsLbTargetGroup() *schema.Resource {
"path": {
Type: schema.TypeString,
Optional: true,
Default: "/",
ValidateFunc: validateAwsLbTargetGroupHealthCheckPath,
},

Expand All @@ -146,27 +145,26 @@ func resourceAwsLbTargetGroup() *schema.Resource {
"timeout": {
Type: schema.TypeInt,
Optional: true,
Default: 5,
Default: 10,
ValidateFunc: validateAwsLbTargetGroupHealthCheckTimeout,
},

"healthy_threshold": {
Type: schema.TypeInt,
Optional: true,
Default: 5,
Default: 3,
ValidateFunc: validateAwsLbTargetGroupHealthCheckHealthyThreshold,
},

"matcher": {
Type: schema.TypeString,
Optional: true,
Default: "200",
},

"unhealthy_threshold": {
Type: schema.TypeInt,
Optional: true,
Default: 2,
Default: 3,
ValidateFunc: validateAwsLbTargetGroupHealthCheckHealthyThreshold,
},
},
Expand Down Expand Up @@ -201,14 +199,17 @@ func resourceAwsLbTargetGroupCreate(d *schema.ResourceData, meta interface{}) er
healthCheck := healthChecks[0].(map[string]interface{})

params.HealthCheckIntervalSeconds = aws.Int64(int64(healthCheck["interval"].(int)))
params.HealthCheckPath = aws.String(healthCheck["path"].(string))
params.HealthCheckPort = aws.String(healthCheck["port"].(string))
params.HealthCheckProtocol = aws.String(healthCheck["protocol"].(string))
params.HealthCheckTimeoutSeconds = aws.Int64(int64(healthCheck["timeout"].(int)))
params.HealthyThresholdCount = aws.Int64(int64(healthCheck["healthy_threshold"].(int)))
params.UnhealthyThresholdCount = aws.Int64(int64(healthCheck["unhealthy_threshold"].(int)))
params.Matcher = &elbv2.Matcher{
HttpCode: aws.String(healthCheck["matcher"].(string)),

if *params.Protocol != "TCP" {
params.HealthCheckTimeoutSeconds = aws.Int64(int64(healthCheck["timeout"].(int)))
params.HealthCheckPath = aws.String(healthCheck["path"].(string))
params.Matcher = &elbv2.Matcher{
HttpCode: aws.String(healthCheck["matcher"].(string)),
}
params.UnhealthyThresholdCount = aws.Int64(int64(healthCheck["unhealthy_threshold"].(int)))
}
}

Expand Down Expand Up @@ -264,17 +265,23 @@ func resourceAwsLbTargetGroupUpdate(d *schema.ResourceData, meta interface{}) er
healthCheck := healthChecks[0].(map[string]interface{})

params = &elbv2.ModifyTargetGroupInput{
TargetGroupArn: aws.String(d.Id()),
HealthCheckIntervalSeconds: aws.Int64(int64(healthCheck["interval"].(int))),
HealthCheckPath: aws.String(healthCheck["path"].(string)),
HealthCheckPort: aws.String(healthCheck["port"].(string)),
HealthCheckProtocol: aws.String(healthCheck["protocol"].(string)),
HealthCheckTimeoutSeconds: aws.Int64(int64(healthCheck["timeout"].(int))),
HealthyThresholdCount: aws.Int64(int64(healthCheck["healthy_threshold"].(int))),
UnhealthyThresholdCount: aws.Int64(int64(healthCheck["unhealthy_threshold"].(int))),
Matcher: &elbv2.Matcher{
TargetGroupArn: aws.String(d.Id()),
HealthCheckPort: aws.String(healthCheck["port"].(string)),
HealthCheckProtocol: aws.String(healthCheck["protocol"].(string)),
HealthyThresholdCount: aws.Int64(int64(healthCheck["healthy_threshold"].(int))),
}

healthCheckProtocol := strings.ToLower(healthCheck["protocol"].(string))

if healthCheckProtocol != "tcp" {
params.Matcher = &elbv2.Matcher{
HttpCode: aws.String(healthCheck["matcher"].(string)),
},
}
params.HealthCheckPath = aws.String(healthCheck["path"].(string))

params.HealthCheckIntervalSeconds = aws.Int64(int64(healthCheck["interval"].(int)))
params.UnhealthyThresholdCount = aws.Int64(int64(healthCheck["unhealthy_threshold"].(int)))
params.HealthCheckIntervalSeconds = aws.Int64(int64(healthCheck["timeout"].(int)))
}
} else {
params = &elbv2.ModifyTargetGroupInput{
Expand Down Expand Up @@ -402,11 +409,11 @@ func validateAwsLbTargetGroupHealthCheckTimeout(v interface{}, k string) (ws []s

func validateAwsLbTargetGroupHealthCheckProtocol(v interface{}, k string) (ws []string, errors []error) {
value := strings.ToLower(v.(string))
if value == "http" || value == "https" {
if value == "http" || value == "https" || value == "tcp" {
return
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation error message below needs to be updated

errors = append(errors, fmt.Errorf("%q must be either %q or %q", k, "HTTP", "HTTPS"))
errors = append(errors, fmt.Errorf("%q must be either %q, %q or %q", k, "HTTP", "HTTPS", "TCP"))
return
}

Expand All @@ -420,11 +427,11 @@ func validateAwsLbTargetGroupPort(v interface{}, k string) (ws []string, errors

func validateAwsLbTargetGroupProtocol(v interface{}, k string) (ws []string, errors []error) {
protocol := strings.ToLower(v.(string))
if protocol == "http" || protocol == "https" {
if protocol == "http" || protocol == "https" || protocol == "tcp" {
return
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation error message below needs to be updated

errors = append(errors, fmt.Errorf("%q must be either %q or %q", k, "HTTP", "HTTPS"))
errors = append(errors, fmt.Errorf("%q must be either %q, %q or %q", k, "HTTP", "HTTPS", "TCP"))
return
}

Expand Down Expand Up @@ -479,13 +486,16 @@ func flattenAwsLbTargetGroupResource(d *schema.ResourceData, meta interface{}, t

healthCheck := make(map[string]interface{})
healthCheck["interval"] = *targetGroup.HealthCheckIntervalSeconds
healthCheck["path"] = *targetGroup.HealthCheckPath
healthCheck["port"] = *targetGroup.HealthCheckPort
healthCheck["protocol"] = *targetGroup.HealthCheckProtocol
healthCheck["timeout"] = *targetGroup.HealthCheckTimeoutSeconds
healthCheck["healthy_threshold"] = *targetGroup.HealthyThresholdCount
healthCheck["unhealthy_threshold"] = *targetGroup.UnhealthyThresholdCount
healthCheck["matcher"] = *targetGroup.Matcher.HttpCode
if *targetGroup.Protocol != "TCP" {
healthCheck["path"] = *targetGroup.HealthCheckPath
healthCheck["matcher"] = *targetGroup.Matcher.HttpCode
}

d.Set("health_check", []interface{}{healthCheck})

attrResp, err := elbconn.DescribeTargetGroupAttributes(&elbv2.DescribeTargetGroupAttributesInput{
Expand Down
33 changes: 33 additions & 0 deletions aws/resource_aws_lb_target_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,39 @@ resource "aws_vpc" "test" {
}`, targetGroupName)
}

func testAccAWSLBTargetGroupConfig_typeTCP(targetGroupName string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This configuration isn't actually used in a test, was the corresponding test omitted?

return fmt.Sprintf(`resource "aws_lb_target_group" "test" {
name = "%s"
port = 8082
protocol = "TCP"
vpc_id = "${aws_vpc.test.id}"

deregistration_delay = 200

stickiness {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stickiness is only applicable to Application Load balancers:

We should take this opportunity to document that as well

type = "lb_cookie"
cookie_duration = 10000
}

health_check {
interval = 30
port = "traffic-port"
protocol = "TCP"
timeout = 10
healthy_threshold = 3
unhealthy_threshold = 3
}
}

resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"

tags {
TestName = "TestAccAWSLBtypeTCP"
}
}`, targetGroupName)
}

func testAccAWSLBTargetGroupConfig_stickiness(targetGroupName string, addStickinessBlock bool, enabled bool) string {
var stickinessBlock string

Expand Down