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

Gateway Load Balancer Support #16131

Merged
merged 10 commits into from
Nov 11, 2020
12 changes: 11 additions & 1 deletion aws/data_source_aws_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"fmt"
"log"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
Expand Down Expand Up @@ -82,6 +83,11 @@ func dataSourceAwsRouteTable() *schema.Resource {
Computed: true,
},

"vpc_endpoint_id": {
Type: schema.TypeString,
Computed: true,
},

"vpc_peering_connection_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -228,7 +234,11 @@ func dataSourceRoutesRead(ec2Routes []*ec2.Route) []map[string]interface{} {
m["egress_only_gateway_id"] = *r.EgressOnlyInternetGatewayId
}
if r.GatewayId != nil {
m["gateway_id"] = *r.GatewayId
if strings.HasPrefix(*r.GatewayId, "vpce-") {
m["vpc_endpoint_id"] = *r.GatewayId
} else {
m["gateway_id"] = *r.GatewayId
}
}
if r.NatGatewayId != nil {
m["nat_gateway_id"] = *r.NatGatewayId
Expand Down
5 changes: 5 additions & 0 deletions aws/resource_aws_default_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func resourceAwsDefaultRouteTable() *schema.Resource {
Optional: true,
},

"vpc_endpoint_id": {
YakDriver marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Optional: true,
},

"vpc_peering_connection_id": {
Type: schema.TypeString,
Optional: true,
Expand Down
159 changes: 159 additions & 0 deletions aws/resource_aws_default_route_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,41 @@ func TestAccAWSDefaultRouteTable_Route_TransitGatewayID(t *testing.T) {
})
}

func TestAccAWSDefaultRouteTable_Route_VpcEndpointId(t *testing.T) {
var routeTable1 ec2.RouteTable
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_default_route_table.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRouteTableDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSDefaultRouteTableConfigRouteVpcEndpointId(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckRouteTableExists(resourceName, &routeTable1),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccAWSDefaultRouteTableImportStateIdFunc(resourceName),
ImportStateVerify: true,
},
// Default route tables do not currently have a method to remove routes during deletion.
// VPC Endpoints will not delete unless the route is removed prior, otherwise will error:
// InvalidParameter: Endpoint must be removed from route table before deletion
{
Config: testAccAWSDefaultRouteTableConfigRouteVpcEndpointIdNoRoute(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckRouteTableExists(resourceName, &routeTable1),
),
},
},
})
}

func TestAccAWSDefaultRouteTable_vpc_endpoint(t *testing.T) {
var v ec2.RouteTable
resourceName := "aws_default_route_table.foo"
Expand Down Expand Up @@ -570,6 +605,130 @@ resource "aws_default_route_table" "test" {
`
}

func testAccAWSDefaultRouteTableConfigRouteVpcEndpointId(rName string) string {
return composeConfig(
testAccAvailableAZsNoOptInConfig(),
fmt.Sprintf(`
data "aws_caller_identity" "current" {}

resource "aws_vpc" "test" {
cidr_block = "10.10.10.0/25"

tags = {
Name = "tf-acc-test-load-balancer"
}
}

# Another route destination for update
resource "aws_internet_gateway" "test" {
vpc_id = aws_vpc.test.id
}

resource "aws_subnet" "test" {
availability_zone = data.aws_availability_zones.available.names[0]
cidr_block = cidrsubnet(aws_vpc.test.cidr_block, 2, 0)
vpc_id = aws_vpc.test.id

tags = {
Name = "tf-acc-test-load-balancer"
}
}

resource "aws_lb" "test" {
load_balancer_type = "gateway"
name = %[1]q

subnet_mapping {
subnet_id = aws_subnet.test.id
}
}

resource "aws_vpc_endpoint_service" "test" {
acceptance_required = false
allowed_principals = [data.aws_caller_identity.current.arn]
gateway_load_balancer_arns = [aws_lb.test.arn]
}

resource "aws_vpc_endpoint" "test" {
service_name = aws_vpc_endpoint_service.test.service_name
subnet_ids = [aws_subnet.test.id]
vpc_endpoint_type = aws_vpc_endpoint_service.test.service_type
vpc_id = aws_vpc.test.id
}

resource "aws_default_route_table" "test" {
default_route_table_id = aws_vpc.test.default_route_table_id

route {
cidr_block = "0.0.0.0/0"
vpc_endpoint_id = aws_vpc_endpoint.test.id
}
}
`, rName))
}

func testAccAWSDefaultRouteTableConfigRouteVpcEndpointIdNoRoute(rName string) string {
return composeConfig(
testAccAvailableAZsNoOptInConfig(),
fmt.Sprintf(`
data "aws_caller_identity" "current" {}

resource "aws_vpc" "test" {
cidr_block = "10.10.10.0/25"

tags = {
Name = "tf-acc-test-load-balancer"
}
}

# Another route destination for update
resource "aws_internet_gateway" "test" {
vpc_id = aws_vpc.test.id
}

resource "aws_subnet" "test" {
availability_zone = data.aws_availability_zones.available.names[0]
cidr_block = cidrsubnet(aws_vpc.test.cidr_block, 2, 0)
vpc_id = aws_vpc.test.id

tags = {
Name = "tf-acc-test-load-balancer"
}
}

resource "aws_lb" "test" {
load_balancer_type = "gateway"
name = %[1]q

subnet_mapping {
subnet_id = aws_subnet.test.id
}
}

resource "aws_vpc_endpoint_service" "test" {
acceptance_required = false
allowed_principals = [data.aws_caller_identity.current.arn]
gateway_load_balancer_arns = [aws_lb.test.arn]
}

resource "aws_vpc_endpoint" "test" {
service_name = aws_vpc_endpoint_service.test.service_name
subnet_ids = [aws_subnet.test.id]
vpc_endpoint_type = aws_vpc_endpoint_service.test.service_type
vpc_id = aws_vpc.test.id
}

resource "aws_default_route_table" "test" {
default_route_table_id = aws_vpc.test.default_route_table_id

route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.test.id
}
}
`, rName))
}

const testAccDefaultRouteTable_vpc_endpoint = `
data "aws_region" "current" {}

Expand Down
13 changes: 5 additions & 8 deletions aws/resource_aws_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,11 @@ func resourceAwsLb() *schema.Resource {
},

"load_balancer_type": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Default: elbv2.LoadBalancerTypeEnumApplication,
ValidateFunc: validation.StringInSlice([]string{
elbv2.LoadBalancerTypeEnumApplication,
elbv2.LoadBalancerTypeEnumNetwork,
}, false),
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Default: elbv2.LoadBalancerTypeEnumApplication,
ValidateFunc: validation.StringInSlice(elbv2.LoadBalancerTypeEnum_Values(), false),
YakDriver marked this conversation as resolved.
Show resolved Hide resolved
},

"security_groups": {
Expand Down
15 changes: 4 additions & 11 deletions aws/resource_aws_lb_target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,10 @@ func resourceAwsLbTargetGroup() *schema.Resource {
},

"protocol": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
elbv2.ProtocolEnumHttp,
elbv2.ProtocolEnumHttps,
elbv2.ProtocolEnumTcp,
elbv2.ProtocolEnumTls,
elbv2.ProtocolEnumUdp,
elbv2.ProtocolEnumTcpUdp,
}, true),
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(elbv2.ProtocolEnum_Values(), true),
YakDriver marked this conversation as resolved.
Show resolved Hide resolved
},

"vpc_id": {
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 @@ -271,6 +271,38 @@ func TestAccAWSLBTargetGroup_networkLB_TargetGroup(t *testing.T) {
})
}

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckAWSLBTargetGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLBTargetGroupConfigProtocolGeneve(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSLBTargetGroupExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "port", "6081"),
resource.TestCheckResourceAttr(resourceName, "protocol", elbv2.ProtocolEnumGeneve),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"lambda_multi_value_headers_enabled",
"proxy_protocol_v2",
"slow_start",
},
},
},
})
}

func TestAccAWSLBTargetGroup_Protocol_Tcp_HealthCheck_Protocol(t *testing.T) {
var targetGroup1, targetGroup2 elbv2.TargetGroup
targetGroupName := fmt.Sprintf("test-target-group-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
Expand Down Expand Up @@ -1430,6 +1462,30 @@ resource "aws_vpc" "test" {
`, targetGroupName)
}

func testAccAWSLBTargetGroupConfigProtocolGeneve(rName string) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
cidr_block = "10.10.10.0/25"

tags = {
Name = "tf-acc-test-lb-target-group"
}
}

resource "aws_lb_target_group" "test" {
name = %[1]q
port = 6081
protocol = "GENEVE"
vpc_id = aws_vpc.test.id

health_check {
port = 80
protocol = "HTTP"
}
}
`, rName)
}

func testAccAWSLBTargetGroupConfigTags1(targetGroupName, tagKey1, tagValue1 string) string {
return fmt.Sprintf(`
resource "aws_lb_target_group" "test" {
Expand Down
Loading