From 479df3b6de40d8972fc086d242e177c33e032159 Mon Sep 17 00:00:00 2001 From: Ryn Daniels Date: Tue, 27 Aug 2019 18:04:48 +0200 Subject: [PATCH 1/2] Import testing for vpn gateway --- aws/resource_aws_vpn_gateway_test.go | 155 +++++++++++++++------------ 1 file changed, 85 insertions(+), 70 deletions(-) diff --git a/aws/resource_aws_vpn_gateway_test.go b/aws/resource_aws_vpn_gateway_test.go index f4c7edb2a319..ac32a598b5b8 100644 --- a/aws/resource_aws_vpn_gateway_test.go +++ b/aws/resource_aws_vpn_gateway_test.go @@ -104,29 +104,9 @@ func testSweepVPNGateways(region string) error { return nil } -func TestAccAWSVpnGateway_importBasic(t *testing.T) { - resourceName := "aws_vpn_gateway.foo" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckVpnGatewayDestroy, - Steps: []resource.TestStep{ - { - Config: testAccVpnGatewayConfig, - }, - - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - func TestAccAWSVpnGateway_basic(t *testing.T) { var v, v2 ec2.VpnGateway + resourceName := "aws_vpn_gateway.test" testNotEqual := func(*terraform.State) error { if len(v.VpcAttachments) == 0 { @@ -147,7 +127,7 @@ func TestAccAWSVpnGateway_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - IDRefreshName: "aws_vpn_gateway.foo", + IDRefreshName: resourceName, Providers: testAccProviders, CheckDestroy: testAccCheckVpnGatewayDestroy, Steps: []resource.TestStep{ @@ -155,15 +135,19 @@ func TestAccAWSVpnGateway_basic(t *testing.T) { Config: testAccVpnGatewayConfig, Check: resource.ComposeTestCheckFunc( testAccCheckVpnGatewayExists( - "aws_vpn_gateway.foo", &v), + resourceName, &v), ), }, - + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, { Config: testAccVpnGatewayConfigChangeVPC, Check: resource.ComposeTestCheckFunc( testAccCheckVpnGatewayExists( - "aws_vpn_gateway.foo", &v2), + resourceName, &v2), testNotEqual, ), }, @@ -173,6 +157,7 @@ func TestAccAWSVpnGateway_basic(t *testing.T) { func TestAccAWSVpnGateway_withAvailabilityZoneSetToState(t *testing.T) { var v ec2.VpnGateway + resourceName := "aws_vpn_gateway.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -182,16 +167,22 @@ func TestAccAWSVpnGateway_withAvailabilityZoneSetToState(t *testing.T) { { Config: testAccVpnGatewayConfigWithAZ, Check: resource.ComposeTestCheckFunc( - testAccCheckVpnGatewayExists("aws_vpn_gateway.foo", &v), + testAccCheckVpnGatewayExists(resourceName, &v), resource.TestCheckResourceAttr( - "aws_vpn_gateway.foo", "availability_zone", "us-west-2a"), + resourceName, "availability_zone", "us-west-2a"), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, }, }) } func TestAccAWSVpnGateway_withAmazonSideAsnSetToState(t *testing.T) { var v ec2.VpnGateway + resourceName := "aws_vpn_gateway.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -201,11 +192,16 @@ func TestAccAWSVpnGateway_withAmazonSideAsnSetToState(t *testing.T) { { Config: testAccVpnGatewayConfigWithASN, Check: resource.ComposeTestCheckFunc( - testAccCheckVpnGatewayExists("aws_vpn_gateway.foo", &v), + testAccCheckVpnGatewayExists(resourceName, &v), resource.TestCheckResourceAttr( - "aws_vpn_gateway.foo", "amazon_side_asn", "4294967294"), + resourceName, "amazon_side_asn", "4294967294"), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -221,7 +217,7 @@ func TestAccAWSVpnGateway_disappears(t *testing.T) { { Config: testAccVpnGatewayConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckVpnGatewayExists("aws_vpn_gateway.foo", &v), + testAccCheckVpnGatewayExists("aws_vpn_gateway.test", &v), testAccAWSVpnGatewayDisappears(&v), ), ExpectNonEmptyPlan: true, @@ -233,6 +229,8 @@ func TestAccAWSVpnGateway_disappears(t *testing.T) { func TestAccAWSVpnGateway_reattach(t *testing.T) { var vpc1, vpc2 ec2.Vpc var vgw1, vgw2 ec2.VpnGateway + resourceName := "aws_vpn_gateway.test" + resourceName2 := "aws_vpn_gateway.test2" testAttachmentFunc := func(vgw *ec2.VpnGateway, vpc *ec2.Vpc) func(*terraform.State) error { return func(*terraform.State) error { @@ -270,30 +268,35 @@ func TestAccAWSVpnGateway_reattach(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - IDRefreshName: "aws_vpn_gateway.foo", + IDRefreshName: resourceName, Providers: testAccProviders, CheckDestroy: testAccCheckVpnGatewayDestroy, Steps: []resource.TestStep{ { Config: testAccCheckVpnGatewayConfigReattach, Check: resource.ComposeTestCheckFunc( - testAccCheckVpcExists("aws_vpc.foo", &vpc1), + testAccCheckVpcExists("aws_vpc.test", &vpc1), testAccCheckVpcExists("aws_vpc.bar", &vpc2), testAccCheckVpnGatewayExists( - "aws_vpn_gateway.foo", &vgw1), + resourceName, &vgw1), testAccCheckVpnGatewayExists( - "aws_vpn_gateway.bar", &vgw2), + resourceName2, &vgw2), testAttachmentFunc(&vgw1, &vpc1), testAttachmentFunc(&vgw2, &vpc2), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, { Config: testAccCheckVpnGatewayConfigReattachChange, Check: resource.ComposeTestCheckFunc( testAccCheckVpnGatewayExists( - "aws_vpn_gateway.foo", &vgw1), + resourceName, &vgw1), testAccCheckVpnGatewayExists( - "aws_vpn_gateway.bar", &vgw2), + resourceName2, &vgw2), testAttachmentFunc(&vgw2, &vpc1), testAttachmentFunc(&vgw1, &vpc2), ), @@ -302,9 +305,9 @@ func TestAccAWSVpnGateway_reattach(t *testing.T) { Config: testAccCheckVpnGatewayConfigReattach, Check: resource.ComposeTestCheckFunc( testAccCheckVpnGatewayExists( - "aws_vpn_gateway.foo", &vgw1), + resourceName, &vgw1), testAccCheckVpnGatewayExists( - "aws_vpn_gateway.bar", &vgw2), + resourceName2, &vgw2), testAttachmentFunc(&vgw1, &vpc1), testAttachmentFunc(&vgw2, &vpc2), ), @@ -315,6 +318,7 @@ func TestAccAWSVpnGateway_reattach(t *testing.T) { func TestAccAWSVpnGateway_delete(t *testing.T) { var vpnGateway ec2.VpnGateway + resourceName := "aws_vpn_gateway.test" testDeleted := func(r string) resource.TestCheckFunc { return func(s *terraform.State) error { @@ -328,18 +332,23 @@ func TestAccAWSVpnGateway_delete(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - IDRefreshName: "aws_vpn_gateway.foo", + IDRefreshName: resourceName, Providers: testAccProviders, CheckDestroy: testAccCheckVpnGatewayDestroy, Steps: []resource.TestStep{ { Config: testAccVpnGatewayConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckVpnGatewayExists("aws_vpn_gateway.foo", &vpnGateway)), + testAccCheckVpnGatewayExists(resourceName, &vpnGateway)), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, }, { Config: testAccNoVpnGatewayConfig, - Check: resource.ComposeTestCheckFunc(testDeleted("aws_vpn_gateway.foo")), + Check: resource.ComposeTestCheckFunc(testDeleted(resourceName)), }, }, }) @@ -347,25 +356,31 @@ func TestAccAWSVpnGateway_delete(t *testing.T) { func TestAccAWSVpnGateway_tags(t *testing.T) { var v ec2.VpnGateway + resourceName := "aws_vpn_gateway.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - IDRefreshName: "aws_vpn_gateway.foo", + IDRefreshName: resourceName, Providers: testAccProviders, CheckDestroy: testAccCheckVpnGatewayDestroy, Steps: []resource.TestStep{ { Config: testAccCheckVpnGatewayConfigTags, Check: resource.ComposeTestCheckFunc( - testAccCheckVpnGatewayExists("aws_vpn_gateway.foo", &v), + testAccCheckVpnGatewayExists(resourceName, &v), testAccCheckTags(&v.Tags, "Name", "terraform-testacc-vpn-gateway-tags"), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, { Config: testAccCheckVpnGatewayConfigTagsUpdate, Check: resource.ComposeTestCheckFunc( - testAccCheckVpnGatewayExists("aws_vpn_gateway.foo", &v), - testAccCheckTags(&v.Tags, "foo", ""), + testAccCheckVpnGatewayExists(resourceName, &v), + testAccCheckTags(&v.Tags, "test", ""), testAccCheckTags(&v.Tags, "Name", "terraform-testacc-vpn-gateway-tags-updated"), ), }, @@ -490,7 +505,7 @@ func testAccCheckVpnGatewayExists(n string, ig *ec2.VpnGateway) resource.TestChe } const testAccNoVpnGatewayConfig = ` -resource "aws_vpc" "foo" { +resource "aws_vpc" "test" { cidr_block = "10.1.0.0/16" tags = { Name = "terraform-testacc-vpn-gateway-removed" @@ -499,15 +514,15 @@ resource "aws_vpc" "foo" { ` const testAccVpnGatewayConfig = ` -resource "aws_vpc" "foo" { +resource "aws_vpc" "test" { cidr_block = "10.1.0.0/16" tags = { Name = "terraform-testacc-vpn-gateway" } } -resource "aws_vpn_gateway" "foo" { - vpc_id = "${aws_vpc.foo.id}" +resource "aws_vpn_gateway" "test" { + vpc_id = "${aws_vpc.test.id}" tags = { Name = "terraform-testacc-vpn-gateway-basic" } @@ -522,7 +537,7 @@ resource "aws_vpc" "bar" { } } -resource "aws_vpn_gateway" "foo" { +resource "aws_vpn_gateway" "test" { vpc_id = "${aws_vpc.bar.id}" tags = { Name = "terraform-testacc-vpn-gateway-basic" @@ -531,15 +546,15 @@ resource "aws_vpn_gateway" "foo" { ` const testAccCheckVpnGatewayConfigTags = ` -resource "aws_vpc" "foo" { +resource "aws_vpc" "test" { cidr_block = "10.1.0.0/16" tags = { Name = "terraform-testacc-vpn-gateway-tags" } } -resource "aws_vpn_gateway" "foo" { - vpc_id = "${aws_vpc.foo.id}" +resource "aws_vpn_gateway" "test" { + vpc_id = "${aws_vpc.test.id}" tags = { Name = "terraform-testacc-vpn-gateway-tags" } @@ -547,15 +562,15 @@ resource "aws_vpn_gateway" "foo" { ` const testAccCheckVpnGatewayConfigTagsUpdate = ` -resource "aws_vpc" "foo" { +resource "aws_vpc" "test" { cidr_block = "10.1.0.0/16" tags = { Name = "terraform-testacc-vpn-gateway-tags" } } -resource "aws_vpn_gateway" "foo" { - vpc_id = "${aws_vpc.foo.id}" +resource "aws_vpn_gateway" "test" { + vpc_id = "${aws_vpc.test.id}" tags = { Name = "terraform-testacc-vpn-gateway-tags-updated" } @@ -563,10 +578,10 @@ resource "aws_vpn_gateway" "foo" { ` const testAccCheckVpnGatewayConfigReattach = ` -resource "aws_vpc" "foo" { +resource "aws_vpc" "test" { cidr_block = "10.1.0.0/16" tags = { - Name = "terraform-testacc-vpn-gateway-reattach-foo" + Name = "terraform-testacc-vpn-gateway-reattach-test" } } @@ -577,8 +592,8 @@ resource "aws_vpc" "bar" { } } -resource "aws_vpn_gateway" "foo" { - vpc_id = "${aws_vpc.foo.id}" +resource "aws_vpn_gateway" "test" { + vpc_id = "${aws_vpc.test.id}" tags = { Name = "terraform-testacc-vpn-gateway-reattach" } @@ -593,10 +608,10 @@ resource "aws_vpn_gateway" "bar" { ` const testAccCheckVpnGatewayConfigReattachChange = ` -resource "aws_vpc" "foo" { +resource "aws_vpc" "test" { cidr_block = "10.1.0.0/16" tags = { - Name = "terraform-testacc-vpn-gateway-reattach-foo" + Name = "terraform-testacc-vpn-gateway-reattach-test" } } @@ -607,7 +622,7 @@ resource "aws_vpc" "bar" { } } -resource "aws_vpn_gateway" "foo" { +resource "aws_vpn_gateway" "test" { vpc_id = "${aws_vpc.bar.id}" tags = { Name = "terraform-testacc-vpn-gateway-reattach" @@ -615,7 +630,7 @@ resource "aws_vpn_gateway" "foo" { } resource "aws_vpn_gateway" "bar" { - vpc_id = "${aws_vpc.foo.id}" + vpc_id = "${aws_vpc.test.id}" tags = { Name = "terraform-testacc-vpn-gateway-reattach" } @@ -623,15 +638,15 @@ resource "aws_vpn_gateway" "bar" { ` const testAccVpnGatewayConfigWithAZ = ` -resource "aws_vpc" "foo" { +resource "aws_vpc" "test" { cidr_block = "10.1.0.0/16" tags = { Name = "terraform-testacc-vpn-gateway-with-az" } } -resource "aws_vpn_gateway" "foo" { - vpc_id = "${aws_vpc.foo.id}" +resource "aws_vpn_gateway" "test" { + vpc_id = "${aws_vpc.test.id}" availability_zone = "us-west-2a" tags = { Name = "terraform-testacc-vpn-gateway-with-az" @@ -640,15 +655,15 @@ resource "aws_vpn_gateway" "foo" { ` const testAccVpnGatewayConfigWithASN = ` -resource "aws_vpc" "foo" { +resource "aws_vpc" "test" { cidr_block = "10.1.0.0/16" tags = { Name = "terraform-testacc-vpn-gateway-with-asn" } } -resource "aws_vpn_gateway" "foo" { - vpc_id = "${aws_vpc.foo.id}" +resource "aws_vpn_gateway" "test" { + vpc_id = "${aws_vpc.test.id}" amazon_side_asn = 4294967294 } ` From aff728e4897ba8ef2c1d28e638254e355e64ec41 Mon Sep 17 00:00:00 2001 From: Ryn Daniels Date: Mon, 2 Sep 2019 12:34:10 +0200 Subject: [PATCH 2/2] Fix test names and ignore broken import --- aws/resource_aws_vpn_gateway_test.go | 29 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/aws/resource_aws_vpn_gateway_test.go b/aws/resource_aws_vpn_gateway_test.go index ac32a598b5b8..30ac1aab8bf6 100644 --- a/aws/resource_aws_vpn_gateway_test.go +++ b/aws/resource_aws_vpn_gateway_test.go @@ -173,9 +173,10 @@ func TestAccAWSVpnGateway_withAvailabilityZoneSetToState(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"availability_zone"}, }, }, }) @@ -276,7 +277,7 @@ func TestAccAWSVpnGateway_reattach(t *testing.T) { Config: testAccCheckVpnGatewayConfigReattach, Check: resource.ComposeTestCheckFunc( testAccCheckVpcExists("aws_vpc.test", &vpc1), - testAccCheckVpcExists("aws_vpc.bar", &vpc2), + testAccCheckVpcExists("aws_vpc.test2", &vpc2), testAccCheckVpnGatewayExists( resourceName, &vgw1), testAccCheckVpnGatewayExists( @@ -530,7 +531,7 @@ resource "aws_vpn_gateway" "test" { ` const testAccVpnGatewayConfigChangeVPC = ` -resource "aws_vpc" "bar" { +resource "aws_vpc" "test2" { cidr_block = "10.2.0.0/16" tags = { Name = "terraform-testacc-vpn-gateway-change-vpc" @@ -538,7 +539,7 @@ resource "aws_vpc" "bar" { } resource "aws_vpn_gateway" "test" { - vpc_id = "${aws_vpc.bar.id}" + vpc_id = "${aws_vpc.test2.id}" tags = { Name = "terraform-testacc-vpn-gateway-basic" } @@ -585,10 +586,10 @@ resource "aws_vpc" "test" { } } -resource "aws_vpc" "bar" { +resource "aws_vpc" "test2" { cidr_block = "10.2.0.0/16" tags = { - Name = "terraform-testacc-vpn-gateway-reattach-bar" + Name = "terraform-testacc-vpn-gateway-reattach-test2" } } @@ -599,8 +600,8 @@ resource "aws_vpn_gateway" "test" { } } -resource "aws_vpn_gateway" "bar" { - vpc_id = "${aws_vpc.bar.id}" +resource "aws_vpn_gateway" "test2" { + vpc_id = "${aws_vpc.test2.id}" tags = { Name = "terraform-testacc-vpn-gateway-reattach" } @@ -615,21 +616,21 @@ resource "aws_vpc" "test" { } } -resource "aws_vpc" "bar" { +resource "aws_vpc" "test2" { cidr_block = "10.2.0.0/16" tags = { - Name = "terraform-testacc-vpn-gateway-reattach-bar" + Name = "terraform-testacc-vpn-gateway-reattach-test2" } } resource "aws_vpn_gateway" "test" { - vpc_id = "${aws_vpc.bar.id}" + vpc_id = "${aws_vpc.test2.id}" tags = { Name = "terraform-testacc-vpn-gateway-reattach" } } -resource "aws_vpn_gateway" "bar" { +resource "aws_vpn_gateway" "test2" { vpc_id = "${aws_vpc.test.id}" tags = { Name = "terraform-testacc-vpn-gateway-reattach"