Skip to content

Commit

Permalink
service/elbv2: Support TLS protocol
Browse files Browse the repository at this point in the history
Reference: #7317

Changes:
* resource/aws_lb_listener: Add `TLS` to `protocol` argument validation
* resource/aws_lb_target_group: Add `TLS` to `protocol` argument validation

Output from acceptance testing:

```
--- PASS: TestAccAWSLBTargetGroup_Protocol_Tls (26.47s)
--- PASS: TestAccAWSLBListener_Protocol_Tls (354.32s)
```
  • Loading branch information
bflad committed Jan 25, 2019
1 parent b10ce7c commit ea5cfc5
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 3 deletions.
1 change: 1 addition & 0 deletions aws/resource_aws_lb_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func resourceAwsLbListener() *schema.Resource {
elbv2.ProtocolEnumHttp,
elbv2.ProtocolEnumHttps,
elbv2.ProtocolEnumTcp,
elbv2.ProtocolEnumTls,
}, true),
},

Expand Down
115 changes: 115 additions & 0 deletions aws/resource_aws_lb_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@ func TestAccAWSLBListener_https(t *testing.T) {
})
}

func TestAccAWSLBListener_Protocol_Tls(t *testing.T) {
var listener1 elbv2.Listener
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_lb_listener.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProvidersWithTLS,
CheckDestroy: testAccCheckAWSLBListenerDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLBListenerConfig_Protocol_Tls(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSLBListenerExists(resourceName, &listener1),
resource.TestCheckResourceAttr(resourceName, "protocol", "TLS"),
),
},
},
})
}

func TestAccAWSLBListener_redirect(t *testing.T) {
var conf elbv2.Listener
lbName := fmt.Sprintf("testlistener-redirect-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
Expand Down Expand Up @@ -716,6 +737,100 @@ resource "tls_self_signed_cert" "example" {
`, lbName, targetGroupName, acctest.RandInt())
}

func testAccAWSLBListenerConfig_Protocol_Tls(rName string) string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {}
resource "tls_private_key" "test" {
algorithm = "RSA"
}
resource "tls_self_signed_cert" "test" {
allowed_uses = [
"key_encipherment",
"digital_signature",
"server_auth",
]
key_algorithm = "RSA"
private_key_pem = "${tls_private_key.test.private_key_pem}"
validity_period_hours = 12
subject {
common_name = "example.com"
organization = "ACME Examples, Inc"
}
}
resource "aws_acm_certificate" "test" {
certificate_body = "${tls_self_signed_cert.test.cert_pem}"
private_key = "${tls_private_key.test.private_key_pem}"
}
resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "tf-acc-test-lb-listener-protocol-tls"
}
}
resource "aws_subnet" "test" {
count = 2
availability_zone = "${data.aws_availability_zones.available.names[count.index]}"
cidr_block = "10.0.${count.index}.0/24"
vpc_id = "${aws_vpc.test.id}"
tags = {
Name = "tf-acc-test-lb-listener-protocol-tls"
}
}
resource "aws_lb" "test" {
internal = true
load_balancer_type = "network"
name = %q
subnets = ["${aws_subnet.test.*.id[0]}", "${aws_subnet.test.*.id[1]}"]
tags = {
Name = "tf-acc-test-lb-listener-protocol-tls"
}
}
resource "aws_lb_target_group" "test" {
name = %q
port = 443
protocol = "TCP"
vpc_id = "${aws_vpc.test.id}"
health_check {
interval = 10
port = "traffic-port"
protocol = "TCP"
healthy_threshold = 3
unhealthy_threshold = 3
}
tags = {
Name = "tf-acc-test-lb-listener-protocol-tls"
}
}
resource "aws_lb_listener" "test" {
certificate_arn = "${aws_acm_certificate.test.arn}"
load_balancer_arn = "${aws_lb.test.arn}"
port = "443"
protocol = "TLS"
ssl_policy = "ELBSecurityPolicy-2016-08"
default_action {
target_group_arn = "${aws_lb_target_group.test.arn}"
type = "forward"
}
}
`, rName, rName)
}

func testAccAWSLBListenerConfig_redirect(lbName string) string {
return fmt.Sprintf(`resource "aws_lb_listener" "front_end" {
load_balancer_arn = "${aws_lb.alb_test.id}"
Expand Down
1 change: 1 addition & 0 deletions aws/resource_aws_lb_target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func resourceAwsLbTargetGroup() *schema.Resource {
elbv2.ProtocolEnumHttp,
elbv2.ProtocolEnumHttps,
elbv2.ProtocolEnumTcp,
elbv2.ProtocolEnumTls,
}, true),
},

Expand Down
52 changes: 52 additions & 0 deletions aws/resource_aws_lb_target_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,27 @@ func TestAccAWSLBTargetGroup_networkLB_TargetGroup(t *testing.T) {
})
}

func TestAccAWSLBTargetGroup_Protocol_Tls(t *testing.T) {
var targetGroup1 elbv2.TargetGroup
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_lb_target_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSLBTargetGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLBTargetGroupConfig_Protocol_Tls(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSLBTargetGroupExists(resourceName, &targetGroup1),
resource.TestCheckResourceAttr(resourceName, "protocol", "TLS"),
),
},
},
})
}

func TestAccAWSLBTargetGroup_networkLB_TargetGroupWithProxy(t *testing.T) {
var confBefore, confAfter elbv2.TargetGroup
targetGroupName := fmt.Sprintf("test-target-group-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
Expand Down Expand Up @@ -1305,6 +1326,37 @@ resource "aws_vpc" "test" {
}`, targetGroupName)
}

func testAccAWSLBTargetGroupConfig_Protocol_Tls(targetGroupName string) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "tf-acc-test-lb-target-group-protocol-tls"
}
}
resource "aws_lb_target_group" "test" {
name = %q
port = 443
protocol = "TLS"
vpc_id = "${aws_vpc.test.id}"
health_check {
interval = 10
port = "traffic-port"
protocol = "TCP"
healthy_threshold = 3
unhealthy_threshold = 3
}
tags = {
Name = "tf-acc-test-lb-target-group-protocol-tls"
}
}
`, targetGroupName)
}

func testAccAWSLBTargetGroupConfig_typeTCP(targetGroupName string) string {
return fmt.Sprintf(`resource "aws_lb_target_group" "test" {
name = "%s"
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/lb_listener.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ The following arguments are supported:

* `load_balancer_arn` - (Required, Forces New Resource) The ARN of the load balancer.
* `port` - (Required) The port on which the load balancer is listening.
* `protocol` - (Optional) The protocol for connections from clients to the load balancer. Valid values are `TCP`, `HTTP` and `HTTPS`. Defaults to `HTTP`.
* `ssl_policy` - (Optional) The name of the SSL Policy for the listener. Required if `protocol` is `HTTPS`.
* `protocol` - (Optional) The protocol for connections from clients to the load balancer. Valid values are `TCP`, `TLS`, `HTTP` and `HTTPS`. Defaults to `HTTP`.
* `ssl_policy` - (Optional) The name of the SSL Policy for the listener. Required if `protocol` is `HTTPS` or `TLS`.
* `certificate_arn` - (Optional) The ARN of the default SSL server certificate. Exactly one certificate is required if the protocol is HTTPS. For adding additional SSL certificates, see the [`aws_lb_listener_certificate` resource](/docs/providers/aws/r/lb_listener_certificate.html).
* `default_action` - (Required) An Action block. Action blocks are documented below.

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/lb_target_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The following arguments are supported:
* `name_prefix` - (Optional, Forces new resource) Creates a unique name beginning with the specified prefix. Conflicts with `name`. Cannot be longer than 6 characters.

* `port` - (Optional) The port on which targets receive traffic, unless overridden when registering a specific target. Required when `target_type` is `instance` or `ip`. Does not apply when `target_type` is `lambda`.
* `protocol` - (Optional) The protocol to use for routing traffic to the targets. Should be one of "TCP", "HTTP" or "HTTPS". Required when `target_type` is `instance` or `ip`. Does not apply when `target_type` is `lambda`.
* `protocol` - (Optional) The protocol to use for routing traffic to the targets. Should be one of "TCP", "TLS", "HTTP" or "HTTPS". Required when `target_type` is `instance` or `ip`. Does not apply when `target_type` is `lambda`.
* `vpc_id` - (Optional) The identifier of the VPC in which to create the target group. Required when `target_type` is `instance` or `ip`. Does not apply when `target_type` is `lambda`.
* `deregistration_delay` - (Optional) The amount time for Elastic Load Balancing to wait before changing the state of a deregistering target from draining to unused. The range is 0-3600 seconds. The default value is 300 seconds.
* `slow_start` - (Optional) The amount time for targets to warm up before the load balancer sends them a full share of requests. The range is 30-900 seconds or 0 to disable. The default value is 0 seconds.
Expand Down

0 comments on commit ea5cfc5

Please sign in to comment.