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

resource/alb_target_group: Add support for UDP protocol #9111

Merged
merged 1 commit into from
Jun 25, 2019
Merged
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
2 changes: 2 additions & 0 deletions aws/resource_aws_lb_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func resourceAwsLbListener() *schema.Resource {
elbv2.ProtocolEnumHttps,
elbv2.ProtocolEnumTcp,
elbv2.ProtocolEnumTls,
elbv2.ProtocolEnumUdp,
elbv2.ProtocolEnumTcpUdp,
}, true),
},

Expand Down
109 changes: 108 additions & 1 deletion aws/resource_aws_lb_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,37 @@ func TestAccAWSLBListener_basic(t *testing.T) {
})
}

func TestAccAWSLBListener_basicUdp(t *testing.T) {
var conf elbv2.Listener
lbName := fmt.Sprintf("testlistener-basic-%s", acctest.RandStringFromCharSet(13, acctest.CharSetAlphaNum))
targetGroupName := fmt.Sprintf("testtargetgroup-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_lb_listener.front_end",
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSLBListenerDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLBListenerConfig_basicUdp(lbName, targetGroupName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSLBListenerExists("aws_lb_listener.front_end", &conf),
resource.TestCheckResourceAttrSet("aws_lb_listener.front_end", "load_balancer_arn"),
resource.TestCheckResourceAttrSet("aws_lb_listener.front_end", "arn"),
resource.TestCheckResourceAttr("aws_lb_listener.front_end", "protocol", "UDP"),
resource.TestCheckResourceAttr("aws_lb_listener.front_end", "port", "514"),
resource.TestCheckResourceAttr("aws_lb_listener.front_end", "default_action.#", "1"),
resource.TestCheckResourceAttr("aws_lb_listener.front_end", "default_action.0.order", "1"),
resource.TestCheckResourceAttr("aws_lb_listener.front_end", "default_action.0.type", "forward"),
resource.TestCheckResourceAttrSet("aws_lb_listener.front_end", "default_action.0.target_group_arn"),
resource.TestCheckResourceAttr("aws_lb_listener.front_end", "default_action.0.redirect.#", "0"),
resource.TestCheckResourceAttr("aws_lb_listener.front_end", "default_action.0.fixed_response.#", "0"),
),
},
},
})
}

func TestAccAWSLBListener_BackwardsCompatibility(t *testing.T) {
var conf elbv2.Listener
lbName := fmt.Sprintf("testlistener-basic-%s", acctest.RandStringFromCharSet(13, acctest.CharSetAlphaNum))
Expand Down Expand Up @@ -506,6 +537,82 @@ resource "aws_security_group" "alb_test" {
`, lbName, targetGroupName)
}

func testAccAWSLBListenerConfig_basicUdp(lbName, targetGroupName string) string {
return fmt.Sprintf(`
resource "aws_lb_listener" "front_end" {
load_balancer_arn = "${aws_lb.alb_test.id}"
protocol = "UDP"
port = "514"

default_action {
target_group_arn = "${aws_lb_target_group.test.id}"
type = "forward"
}
}

resource "aws_lb" "alb_test" {
name = "%s"
internal = false
load_balancer_type = "network"
subnets = ["${aws_subnet.alb_test.*.id[0]}", "${aws_subnet.alb_test.*.id[1]}"]

idle_timeout = 30
enable_deletion_protection = false

tags = {
Name = "TestAccAWSALB_basic"
}
}

resource "aws_lb_target_group" "test" {
name = "%s"
port = 514
protocol = "UDP"
vpc_id = "${aws_vpc.alb_test.id}"

health_check {
port = 514
protocol = "TCP"
}
}

variable "subnets" {
default = ["10.0.1.0/24", "10.0.2.0/24"]
type = "list"
}

data "aws_availability_zones" "available" {}

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

tags = {
Name = "terraform-testacc-lb-listener-basic"
}
}

resource "aws_internet_gateway" "gw" {
vpc_id = "${aws_vpc.alb_test.id}"

tags = {
Name = "TestAccAWSALB_basic"
}
}

resource "aws_subnet" "alb_test" {
count = 2
vpc_id = "${aws_vpc.alb_test.id}"
cidr_block = "${element(var.subnets, count.index)}"
map_public_ip_on_launch = true
availability_zone = "${element(data.aws_availability_zones.available.names, count.index)}"

tags = {
Name = "tf-acc-lb-listener-basic-${count.index}"
}
}
`, lbName, targetGroupName)
}

func testAccAWSLBListenerConfigBackwardsCompatibility(lbName, targetGroupName string) string {
return fmt.Sprintf(`
resource "aws_alb_listener" "front_end" {
Expand All @@ -521,7 +628,7 @@ resource "aws_alb_listener" "front_end" {

resource "aws_alb" "alb_test" {
name = "%s"
internal = true
internal = false
stack72 marked this conversation as resolved.
Show resolved Hide resolved
security_groups = ["${aws_security_group.alb_test.id}"]
subnets = ["${aws_subnet.alb_test.*.id[0]}", "${aws_subnet.alb_test.*.id[1]}"]

Expand Down
2 changes: 2 additions & 0 deletions aws/resource_aws_lb_target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func resourceAwsLbTargetGroup() *schema.Resource {
elbv2.ProtocolEnumHttps,
elbv2.ProtocolEnumTcp,
elbv2.ProtocolEnumTls,
elbv2.ProtocolEnumUdp,
elbv2.ProtocolEnumTcpUdp,
}, true),
},

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

func TestAccAWSLBTargetGroup_basicUdp(t *testing.T) {
var conf elbv2.TargetGroup
targetGroupName := fmt.Sprintf("test-target-group-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_lb_target_group.test",
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSLBTargetGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLBTargetGroupConfig_basicUdp(targetGroupName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSLBTargetGroupExists("aws_lb_target_group.test", &conf),
resource.TestCheckResourceAttrSet("aws_lb_target_group.test", "arn"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "name", targetGroupName),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "port", "514"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "protocol", "UDP"),
resource.TestCheckResourceAttrSet("aws_lb_target_group.test", "vpc_id"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "health_check.#", "1"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "health_check.0.port", "514"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "health_check.0.protocol", "TCP"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "tags.%", "1"),
resource.TestCheckResourceAttr("aws_lb_target_group.test", "tags.TestName", "TestAccAWSLBTargetGroup_basic"),
),
},
},
})
}

func TestAccAWSLBTargetGroup_withoutHealthcheck(t *testing.T) {
var conf elbv2.TargetGroup
targetGroupName := fmt.Sprintf("test-target-group-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
Expand Down Expand Up @@ -1148,6 +1178,32 @@ resource "aws_vpc" "test" {
}`, targetGroupName)
}

func testAccAWSLBTargetGroupConfig_basicUdp(targetGroupName string) string {
return fmt.Sprintf(`resource "aws_lb_target_group" "test" {
name = "%s"
port = 514
protocol = "UDP"
vpc_id = "${aws_vpc.test.id}"

health_check {
protocol = "TCP"
port = 514
}

tags = {
TestName = "TestAccAWSLBTargetGroup_basic"
}
}

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

tags = {
TestName = "terraform-testacc-lb-target-group-basic"
}
}`, targetGroupName)
}

func testAccAWSLBTargetGroupConfig_withoutHealthcheck(targetGroupName string) string {
return fmt.Sprintf(`resource "aws_lb_target_group" "test" {
name = "%s"
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/lb_listener.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ 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`, `TLS`, `HTTP` and `HTTPS`. Defaults to `HTTP`.
* `protocol` - (Optional) The protocol for connections from clients to the load balancer. Valid values are `TCP`, `TLS`, `UDP`, `TCP_UDP`, `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, Forces new resource) 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, Forces new resource) 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`.
* `protocol` - (Optional, Forces new resource) The protocol to use for routing traffic to the targets. Should be one of "TCP", "TLS", "UDP", "TCP_UDP", "HTTP" or "HTTPS". Required when `target_type` is `instance` or `ip`. Does not apply when `target_type` is `lambda`.
* `vpc_id` - (Optional, Forces new resource) 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