Skip to content

Commit

Permalink
r/aws_default_route_table: Add acceptance tests from hashicorp#16131.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Nov 30, 2020
1 parent 67a041c commit c72ecc9
Showing 1 changed file with 161 additions and 2 deletions.
163 changes: 161 additions & 2 deletions aws/resource_aws_default_route_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,41 @@ func TestAccAWSDefaultRouteTable_IPv4_To_TransitGateway(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_VpcEndpointAssociation(t *testing.T) {
var routeTable ec2.RouteTable
resourceName := "aws_default_route_table.test"
Expand Down Expand Up @@ -278,8 +313,6 @@ func TestAccAWSDefaultRouteTable_tags(t *testing.T) {
var routeTable ec2.RouteTable
resourceName := "aws_default_route_table.test"
rName := acctest.RandomWithPrefix("tf-acc-test")
destinationCidr := "10.2.0.0/16"
destinationIpv6Cidr := "::/0"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -320,6 +353,8 @@ func TestAccAWSDefaultRouteTable_ConditionalCidrBlock(t *testing.T) {
resourceName := "aws_default_route_table.test"
igwResourceName := "aws_internet_gateway.test"
rName := acctest.RandomWithPrefix("tf-acc-test")
destinationCidr := "10.2.0.0/16"
destinationIpv6Cidr := "::/0"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -617,6 +652,130 @@ resource "aws_default_route_table" "test" {
`, rName, destinationCidr))
}

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))
}

func testAccDefaultRouteTableConfigVpcEndpointAssociation(rName, destinationCidr string) string {
return fmt.Sprintf(`
data "aws_region" "current" {}
Expand Down

0 comments on commit c72ecc9

Please sign in to comment.