Skip to content

Commit

Permalink
r/aws_route: Rework 'TestAccAWSRoute_ConditionalCidrBlock'.
Browse files Browse the repository at this point in the history
Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRoute_ConditionalCidrBlock'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRoute_ConditionalCidrBlock -timeout 120m
=== RUN   TestAccAWSRoute_ConditionalCidrBlock
=== PAUSE TestAccAWSRoute_ConditionalCidrBlock
=== CONT  TestAccAWSRoute_ConditionalCidrBlock
--- PASS: TestAccAWSRoute_ConditionalCidrBlock (76.68s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	76.752s
  • Loading branch information
ewbankkit committed Aug 22, 2020
1 parent 0e75d74 commit 25aea89
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions aws/resource_aws_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,26 +638,28 @@ func TestAccAWSRoute_ConditionalCidrBlock(t *testing.T) {
var route ec2.Route
resourceName := "aws_route.test"
rName := acctest.RandomWithPrefix("tf-acc-test")
destinationCidr := "10.2.0.0/16"
destinationIpv6Cidr := "::/0"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSRouteDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSRouteConfigConditionalIpv4Ipv6(rName, false),
Config: testAccAWSRouteConfigConditionalIpv4Ipv6(rName, destinationCidr, destinationIpv6Cidr, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRouteExists(resourceName, &route),
resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", "0.0.0.0/0"),
resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr),
resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""),
),
},
{
Config: testAccAWSRouteConfigConditionalIpv4Ipv6(rName, true),
Config: testAccAWSRouteConfigConditionalIpv4Ipv6(rName, destinationCidr, destinationIpv6Cidr, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRouteExists(resourceName, &route),
resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", ""),
resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", "::/0"),
resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", destinationIpv6Cidr),
),
},
{
Expand Down Expand Up @@ -1128,7 +1130,7 @@ resource "aws_route" "test" {
`, rName, destinationCidr)
}

func testAccAWSRouteConfigConditionalIpv4Ipv6(rName string, ipv6Route bool) string {
func testAccAWSRouteConfigConditionalIpv4Ipv6(rName, destinationCidr, destinationIpv6Cidr string, ipv6Route bool) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
cidr_block = "10.1.0.0/16"
Expand All @@ -1139,14 +1141,6 @@ resource "aws_vpc" "test" {
}
}
resource "aws_egress_only_internet_gateway" "test" {
vpc_id = aws_vpc.test.id
tags = {
Name = %[1]q
}
}
resource "aws_internet_gateway" "test" {
vpc_id = aws_vpc.test.id
Expand All @@ -1164,9 +1158,9 @@ resource "aws_route_table" "test" {
}
locals {
ipv6 = %[2]t
destination = "0.0.0.0/0"
destination_ipv6 = "::/0"
ipv6 = %[4]t
destination = %[2]q
destination_ipv6 = %[3]q
}
resource "aws_route" "test" {
Expand All @@ -1176,7 +1170,7 @@ resource "aws_route" "test" {
destination_cidr_block = local.ipv6 ? "" : local.destination
destination_ipv6_cidr_block = local.ipv6 ? local.destination_ipv6 : ""
}
`, rName, ipv6Route)
`, rName, destinationCidr, destinationIpv6Cidr, ipv6Route)
}

func testAccAWSRouteConfigIpv4Instance(rName, destinationCidr string) string {
Expand Down Expand Up @@ -1360,7 +1354,7 @@ resource "aws_subnet" "test" {
}
resource "aws_internet_gateway" "test" {
vpc_id = "${aws_vpc.test.id}"
vpc_id = aws_vpc.test.id
tags = {
Name = %[1]q
Expand Down

0 comments on commit 25aea89

Please sign in to comment.