Skip to content

Commit

Permalink
r/aws_route: Add 'TestAccAWSRoute_IPv4_To_NetworkInterface_Attached' …
Browse files Browse the repository at this point in the history
…to test route to ENI attached to an instance.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSRoute_IPv4_To_NetworkInterface_Attached'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSRoute_IPv4_To_NetworkInterface_Attached -timeout 120m
=== RUN   TestAccAWSRoute_IPv4_To_NetworkInterface_Attached
=== PAUSE TestAccAWSRoute_IPv4_To_NetworkInterface_Attached
=== CONT  TestAccAWSRoute_IPv4_To_NetworkInterface_Attached
--- PASS: TestAccAWSRoute_IPv4_To_NetworkInterface_Attached (113.54s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	113.607s
  • Loading branch information
ewbankkit committed Aug 22, 2020
1 parent 25aea89 commit 4b145ff
Showing 1 changed file with 125 additions and 6 deletions.
131 changes: 125 additions & 6 deletions aws/resource_aws_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func TestAccAWSRoute_IPv6_To_Instance(t *testing.T) {
})
}

func TestAccAWSRoute_IPv6_To_NetworkInterface(t *testing.T) {
func TestAccAWSRoute_IPv6_To_NetworkInterface_Unattached(t *testing.T) {
var route ec2.Route
resourceName := "aws_route.test"
eniResourceName := "aws_network_interface.test"
Expand All @@ -246,7 +246,7 @@ func TestAccAWSRoute_IPv6_To_NetworkInterface(t *testing.T) {
CheckDestroy: testAccCheckAWSRouteDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSRouteConfigIpv6NetworkInterface(rName, destinationCidr),
Config: testAccAWSRouteConfigIpv6NetworkInterfaceUnattached(rName, destinationCidr),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRouteExists(resourceName, &route),
resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", ""),
Expand Down Expand Up @@ -438,7 +438,7 @@ func TestAccAWSRoute_IPv4_To_Instance(t *testing.T) {
})
}

func TestAccAWSRoute_IPv4_To_NetworkInterface(t *testing.T) {
func TestAccAWSRoute_IPv4_To_NetworkInterface_Unattached(t *testing.T) {
var route ec2.Route
resourceName := "aws_route.test"
eniResourceName := "aws_network_interface.test"
Expand All @@ -453,7 +453,7 @@ func TestAccAWSRoute_IPv4_To_NetworkInterface(t *testing.T) {
CheckDestroy: testAccCheckAWSRouteDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSRouteConfigIpv4NetworkInterface(rName, destinationCidr),
Config: testAccAWSRouteConfigIpv4NetworkInterfaceUnattached(rName, destinationCidr),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRouteExists(resourceName, &route),
resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr),
Expand Down Expand Up @@ -481,6 +481,50 @@ func TestAccAWSRoute_IPv4_To_NetworkInterface(t *testing.T) {
})
}

func TestAccAWSRoute_IPv4_To_NetworkInterface_Attached(t *testing.T) {
var route ec2.Route
resourceName := "aws_route.test"
eniResourceName := "aws_network_interface.test"
instanceResourceName := "aws_instance.test"
rName := acctest.RandomWithPrefix("tf-acc-test")
destinationCidr := "10.3.0.0/16"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSRouteDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSRouteConfigIpv4NetworkInterfaceAttached(rName, destinationCidr),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRouteExists(resourceName, &route),
resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", destinationCidr),
resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", ""),
resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""),
resource.TestCheckResourceAttr(resourceName, "egress_only_gateway_id", ""),
resource.TestCheckResourceAttr(resourceName, "gateway_id", ""),
resource.TestCheckResourceAttrPair(resourceName, "instance_id", instanceResourceName, "id"),
testAccCheckResourceAttrAccountID(resourceName, "instance_owner_id"),
resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""),
resource.TestCheckResourceAttrPair(resourceName, "network_interface_id", eniResourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute),
resource.TestCheckResourceAttr(resourceName, "state", ec2.RouteStateActive),
resource.TestCheckResourceAttr(resourceName, "transit_gateway_id", ""),
resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccAWSRouteImportStateIdFunc(resourceName),
ImportStateVerify: true,
},
},
})
}

func TestAccAWSRoute_IPv4_To_VpcPeeringConnection(t *testing.T) {
var route ec2.Route
resourceName := "aws_route.test"
Expand Down Expand Up @@ -820,7 +864,7 @@ resource "aws_route" "test" {
`, rName, destinationCidr)
}

func testAccAWSRouteConfigIpv6NetworkInterface(rName, destinationCidr string) string {
func testAccAWSRouteConfigIpv6NetworkInterfaceUnattached(rName, destinationCidr string) string {
return fmt.Sprintf(`
data "aws_availability_zones" "current" {
# Exclude usw2-az4 (us-west-2d) as it has limited instance types.
Expand Down Expand Up @@ -1233,7 +1277,7 @@ resource "aws_route" "test" {
`, rName, destinationCidr))
}

func testAccAWSRouteConfigIpv4NetworkInterface(rName, destinationCidr string) string {
func testAccAWSRouteConfigIpv4NetworkInterfaceUnattached(rName, destinationCidr string) string {
return fmt.Sprintf(`
data "aws_availability_zones" "current" {
# Exclude usw2-az4 (us-west-2d) as it has limited instance types.
Expand Down Expand Up @@ -1288,6 +1332,81 @@ resource "aws_route" "test" {
`, rName, destinationCidr)
}

func testAccAWSRouteConfigIpv4NetworkInterfaceAttached(rName, destinationCidr string) string {
return composeConfig(
testAccLatestAmazonLinuxHvmEbsAmiConfig(),
testAccAvailableEc2InstanceTypeForRegion("t3.micro", "t2.micro"),
fmt.Sprintf(`
data "aws_availability_zones" "current" {
# Exclude usw2-az4 (us-west-2d) as it has limited instance types.
exclude_zone_ids = ["usw2-az4"]
state = "available"
filter {
name = "opt-in-status"
values = ["opt-in-not-required"]
}
}
resource "aws_vpc" "test" {
cidr_block = "10.1.0.0/16"
tags = {
Name = %[1]q
}
}
resource "aws_subnet" "test" {
cidr_block = "10.1.1.0/24"
vpc_id = aws_vpc.test.id
availability_zone = data.aws_availability_zones.current.names[0]
tags = {
Name = %[1]q
}
}
resource "aws_network_interface" "test" {
subnet_id = aws_subnet.test.id
tags = {
Name = %[1]q
}
}
resource "aws_instance" "test" {
ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id
instance_type = data.aws_ec2_instance_type_offering.available.instance_type
network_interface {
device_index = 0
network_interface_id = aws_network_interface.test.id
}
tags = {
Name = %[1]q
}
}
resource "aws_route_table" "test" {
vpc_id = aws_vpc.test.id
tags = {
Name = %[1]q
}
}
resource "aws_route" "test" {
route_table_id = aws_route_table.test.id
destination_cidr_block = %[2]q
network_interface_id = aws_network_interface.test.id
# Wait for the ENI attachment.
depends_on = [aws_instance.test]
}
`, rName, destinationCidr))
}

func testAccAWSRouteConfigIpv4VpcPeeringConnection(rName, destinationCidr string) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
Expand Down

0 comments on commit 4b145ff

Please sign in to comment.