diff --git a/.changelog/12482.txt b/.changelog/12482.txt new file mode 100644 index 00000000000..f8a17f14080 --- /dev/null +++ b/.changelog/12482.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_dx_gateway_association: Changes to `proposal_id` do not force resource recreation +``` diff --git a/aws/resource_aws_dx_gateway_association.go b/aws/resource_aws_dx_gateway_association.go index bb237b99f41..a574640275e 100644 --- a/aws/resource_aws_dx_gateway_association.go +++ b/aws/resource_aws_dx_gateway_association.go @@ -82,10 +82,17 @@ func resourceAwsDxGatewayAssociation() *schema.Resource { }, "proposal_id": { + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"associated_gateway_id", "vpn_gateway_id"}, + }, + + "vpn_gateway_id": { Type: schema.TypeString, Optional: true, ForceNew: true, - ConflictsWith: []string{"associated_gateway_id"}, + ConflictsWith: []string{"associated_gateway_id", "associated_gateway_owner_account_id", "proposal_id"}, + Deprecated: "use 'associated_gateway_id' argument instead", }, }, diff --git a/aws/resource_aws_dx_gateway_association_test.go b/aws/resource_aws_dx_gateway_association_test.go index 3b5eacc1085..ee7f28d5e33 100644 --- a/aws/resource_aws_dx_gateway_association_test.go +++ b/aws/resource_aws_dx_gateway_association_test.go @@ -185,8 +185,10 @@ func testSweepDirectConnectGatewayAssociations(region string) error { // V0 state upgrade testing must be done via acceptance testing due to API call func TestAccAwsDxGatewayAssociation_V0StateUpgrade(t *testing.T) { resourceName := "aws_dx_gateway_association.test" - rName := fmt.Sprintf("terraform-testacc-dxgwassoc-%d", acctest.RandInt()) + rName := acctest.RandomWithPrefix("tf-acc-test") rBgpAsn := acctest.RandIntRange(64512, 65534) + var ga directconnect.GatewayAssociation + var gap directconnect.GatewayAssociationProposal resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -196,7 +198,7 @@ func TestAccAwsDxGatewayAssociation_V0StateUpgrade(t *testing.T) { { Config: testAccDxGatewayAssociationConfig_basicVpnGatewaySingleAccount(rName, rBgpAsn), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsDxGatewayAssociationExists(resourceName), + testAccCheckAwsDxGatewayAssociationExists(resourceName, &ga, &gap), testAccCheckAwsDxGatewayAssociationStateUpgradeV0(resourceName), ), }, @@ -208,8 +210,10 @@ func TestAccAwsDxGatewayAssociation_basicVpnGatewaySingleAccount(t *testing.T) { resourceName := "aws_dx_gateway_association.test" resourceNameDxGw := "aws_dx_gateway.test" resourceNameVgw := "aws_vpn_gateway.test" - rName := fmt.Sprintf("terraform-testacc-dxgwassoc-%d", acctest.RandInt()) + rName := acctest.RandomWithPrefix("tf-acc-test") rBgpAsn := acctest.RandIntRange(64512, 65534) + var ga directconnect.GatewayAssociation + var gap directconnect.GatewayAssociationProposal resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -219,7 +223,7 @@ func TestAccAwsDxGatewayAssociation_basicVpnGatewaySingleAccount(t *testing.T) { { Config: testAccDxGatewayAssociationConfig_basicVpnGatewaySingleAccount(rName, rBgpAsn), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsDxGatewayAssociationExists(resourceName), + testAccCheckAwsDxGatewayAssociationExists(resourceName, &ga, &gap), resource.TestCheckResourceAttrPair(resourceName, "dx_gateway_id", resourceNameDxGw, "id"), resource.TestCheckResourceAttrPair(resourceName, "associated_gateway_id", resourceNameVgw, "id"), resource.TestCheckResourceAttrSet(resourceName, "dx_gateway_association_id"), @@ -231,15 +235,8 @@ func TestAccAwsDxGatewayAssociation_basicVpnGatewaySingleAccount(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportStateIdFunc: func(s *terraform.State) (string, error) { - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return "", fmt.Errorf("Not Found: %s", resourceName) - } - - return fmt.Sprintf("%s/%s", rs.Primary.Attributes["dx_gateway_id"], rs.Primary.Attributes["associated_gateway_id"]), nil - }, + ResourceName: resourceName, + ImportStateIdFunc: testAccAwsDxGatewayAssociationImportStateIdFunc(resourceName), ImportState: true, ImportStateVerify: true, }, @@ -252,8 +249,10 @@ func TestAccAwsDxGatewayAssociation_basicVpnGatewayCrossAccount(t *testing.T) { resourceName := "aws_dx_gateway_association.test" resourceNameDxGw := "aws_dx_gateway.test" resourceNameVgw := "aws_vpn_gateway.test" - rName := fmt.Sprintf("terraform-testacc-dxgwassoc-%d", acctest.RandInt()) + rName := acctest.RandomWithPrefix("tf-acc-test") rBgpAsn := acctest.RandIntRange(64512, 65534) + var ga directconnect.GatewayAssociation + var gap directconnect.GatewayAssociationProposal resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { @@ -266,7 +265,7 @@ func TestAccAwsDxGatewayAssociation_basicVpnGatewayCrossAccount(t *testing.T) { { Config: testAccDxGatewayAssociationConfig_basicVpnGatewayCrossAccount(rName, rBgpAsn), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsDxGatewayAssociationExists(resourceName), + testAccCheckAwsDxGatewayAssociationExists(resourceName, &ga, &gap), resource.TestCheckResourceAttrPair(resourceName, "dx_gateway_id", resourceNameDxGw, "id"), resource.TestCheckResourceAttrPair(resourceName, "associated_gateway_id", resourceNameVgw, "id"), resource.TestCheckResourceAttrSet(resourceName, "dx_gateway_association_id"), @@ -286,8 +285,10 @@ func TestAccAwsDxGatewayAssociation_basicTransitGatewaySingleAccount(t *testing. resourceName := "aws_dx_gateway_association.test" resourceNameDxGw := "aws_dx_gateway.test" resourceNameTgw := "aws_ec2_transit_gateway.test" - rName := fmt.Sprintf("terraform-testacc-dxgwassoc-%d", acctest.RandInt()) + rName := acctest.RandomWithPrefix("tf-acc-test") rBgpAsn := acctest.RandIntRange(64512, 65534) + var ga directconnect.GatewayAssociation + var gap directconnect.GatewayAssociationProposal resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -297,7 +298,7 @@ func TestAccAwsDxGatewayAssociation_basicTransitGatewaySingleAccount(t *testing. { Config: testAccDxGatewayAssociationConfig_basicTransitGatewaySingleAccount(rName, rBgpAsn), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsDxGatewayAssociationExists(resourceName), + testAccCheckAwsDxGatewayAssociationExists(resourceName, &ga, &gap), resource.TestCheckResourceAttrPair(resourceName, "dx_gateway_id", resourceNameDxGw, "id"), resource.TestCheckResourceAttrPair(resourceName, "associated_gateway_id", resourceNameTgw, "id"), resource.TestCheckResourceAttrSet(resourceName, "dx_gateway_association_id"), @@ -310,15 +311,8 @@ func TestAccAwsDxGatewayAssociation_basicTransitGatewaySingleAccount(t *testing. ), }, { - ResourceName: resourceName, - ImportStateIdFunc: func(s *terraform.State) (string, error) { - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return "", fmt.Errorf("Not Found: %s", resourceName) - } - - return fmt.Sprintf("%s/%s", rs.Primary.Attributes["dx_gateway_id"], rs.Primary.Attributes["associated_gateway_id"]), nil - }, + ResourceName: resourceName, + ImportStateIdFunc: testAccAwsDxGatewayAssociationImportStateIdFunc(resourceName), ImportState: true, ImportStateVerify: true, }, @@ -331,8 +325,10 @@ func TestAccAwsDxGatewayAssociation_basicTransitGatewayCrossAccount(t *testing.T resourceName := "aws_dx_gateway_association.test" resourceNameDxGw := "aws_dx_gateway.test" resourceNameTgw := "aws_ec2_transit_gateway.test" - rName := fmt.Sprintf("terraform-testacc-dxgwassoc-%d", acctest.RandInt()) + rName := acctest.RandomWithPrefix("tf-acc-test") rBgpAsn := acctest.RandIntRange(64512, 65534) + var ga directconnect.GatewayAssociation + var gap directconnect.GatewayAssociationProposal resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { @@ -345,7 +341,7 @@ func TestAccAwsDxGatewayAssociation_basicTransitGatewayCrossAccount(t *testing.T { Config: testAccDxGatewayAssociationConfig_basicTransitGatewayCrossAccount(rName, rBgpAsn), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsDxGatewayAssociationExists(resourceName), + testAccCheckAwsDxGatewayAssociationExists(resourceName, &ga, &gap), resource.TestCheckResourceAttrPair(resourceName, "dx_gateway_id", resourceNameDxGw, "id"), resource.TestCheckResourceAttrPair(resourceName, "associated_gateway_id", resourceNameTgw, "id"), resource.TestCheckResourceAttrSet(resourceName, "dx_gateway_association_id"), @@ -363,11 +359,12 @@ func TestAccAwsDxGatewayAssociation_basicTransitGatewayCrossAccount(t *testing.T } func TestAccAwsDxGatewayAssociation_multiVpnGatewaysSingleAccount(t *testing.T) { - resourceName1 := "aws_dx_gateway_association.test1" - resourceName2 := "aws_dx_gateway_association.test2" - rName1 := fmt.Sprintf("terraform-testacc-dxgwassoc-%d", acctest.RandInt()) - rName2 := fmt.Sprintf("terraform-testacc-dxgwassoc-%d", acctest.RandInt()) + resourceName1 := "aws_dx_gateway_association.test.0" + resourceName2 := "aws_dx_gateway_association.test.1" + rName := acctest.RandomWithPrefix("tf-acc-test") rBgpAsn := acctest.RandIntRange(64512, 65534) + var ga directconnect.GatewayAssociation + var gap directconnect.GatewayAssociationProposal resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -375,16 +372,16 @@ func TestAccAwsDxGatewayAssociation_multiVpnGatewaysSingleAccount(t *testing.T) CheckDestroy: testAccCheckAwsDxGatewayAssociationDestroy, Steps: []resource.TestStep{ { - Config: testAccDxGatewayAssociationConfig_multiVpnGatewaysSingleAccount(rName1, rName2, rBgpAsn), + Config: testAccDxGatewayAssociationConfig_multiVpnGatewaysSingleAccount(rName, rBgpAsn), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsDxGatewayAssociationExists(resourceName1), - testAccCheckAwsDxGatewayAssociationExists(resourceName2), + testAccCheckAwsDxGatewayAssociationExists(resourceName1, &ga, &gap), + testAccCheckAwsDxGatewayAssociationExists(resourceName2, &ga, &gap), resource.TestCheckResourceAttrSet(resourceName1, "dx_gateway_association_id"), resource.TestCheckResourceAttr(resourceName1, "allowed_prefixes.#", "1"), - resource.TestCheckTypeSetElemAttr(resourceName1, "allowed_prefixes.*", "10.255.255.16/28"), + resource.TestCheckTypeSetElemAttr(resourceName1, "allowed_prefixes.*", "10.255.255.0/28"), resource.TestCheckResourceAttrSet(resourceName2, "dx_gateway_association_id"), resource.TestCheckResourceAttr(resourceName2, "allowed_prefixes.#", "1"), - resource.TestCheckTypeSetElemAttr(resourceName2, "allowed_prefixes.*", "10.255.255.32/28"), + resource.TestCheckTypeSetElemAttr(resourceName2, "allowed_prefixes.*", "10.255.255.16/28"), ), }, }, @@ -395,8 +392,10 @@ func TestAccAwsDxGatewayAssociation_allowedPrefixesVpnGatewaySingleAccount(t *te resourceName := "aws_dx_gateway_association.test" resourceNameDxGw := "aws_dx_gateway.test" resourceNameVgw := "aws_vpn_gateway.test" - rName := fmt.Sprintf("terraform-testacc-dxgwassoc-%d", acctest.RandInt()) + rName := acctest.RandomWithPrefix("tf-acc-test") rBgpAsn := acctest.RandIntRange(64512, 65534) + var ga directconnect.GatewayAssociation + var gap directconnect.GatewayAssociationProposal resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -406,7 +405,7 @@ func TestAccAwsDxGatewayAssociation_allowedPrefixesVpnGatewaySingleAccount(t *te { Config: testAccDxGatewayAssociationConfig_allowedPrefixesVpnGatewaySingleAccount(rName, rBgpAsn), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsDxGatewayAssociationExists(resourceName), + testAccCheckAwsDxGatewayAssociationExists(resourceName, &ga, &gap), resource.TestCheckResourceAttrPair(resourceName, "dx_gateway_id", resourceNameDxGw, "id"), resource.TestCheckResourceAttrPair(resourceName, "associated_gateway_id", resourceNameVgw, "id"), resource.TestCheckResourceAttrSet(resourceName, "dx_gateway_association_id"), @@ -415,10 +414,16 @@ func TestAccAwsDxGatewayAssociation_allowedPrefixesVpnGatewaySingleAccount(t *te resource.TestCheckTypeSetElemAttr(resourceName, "allowed_prefixes.*", "10.255.255.8/30"), ), }, + { + ResourceName: resourceName, + ImportStateIdFunc: testAccAwsDxGatewayAssociationImportStateIdFunc(resourceName), + ImportState: true, + ImportStateVerify: true, + }, { Config: testAccDxGatewayAssociationConfig_allowedPrefixesVpnGatewaySingleAccountUpdated(rName, rBgpAsn), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsDxGatewayAssociationExists(resourceName), + testAccCheckAwsDxGatewayAssociationExists(resourceName, &ga, &gap), resource.TestCheckResourceAttr(resourceName, "allowed_prefixes.#", "1"), resource.TestCheckTypeSetElemAttr(resourceName, "allowed_prefixes.*", "10.255.255.8/29"), ), @@ -432,8 +437,10 @@ func TestAccAwsDxGatewayAssociation_allowedPrefixesVpnGatewayCrossAccount(t *tes resourceName := "aws_dx_gateway_association.test" resourceNameDxGw := "aws_dx_gateway.test" resourceNameVgw := "aws_vpn_gateway.test" - rName := fmt.Sprintf("terraform-testacc-dxgwassoc-%d", acctest.RandInt()) + rName := acctest.RandomWithPrefix("tf-acc-test") rBgpAsn := acctest.RandIntRange(64512, 65534) + var ga directconnect.GatewayAssociation + var gap directconnect.GatewayAssociationProposal resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { @@ -446,7 +453,7 @@ func TestAccAwsDxGatewayAssociation_allowedPrefixesVpnGatewayCrossAccount(t *tes { Config: testAccDxGatewayAssociationConfig_allowedPrefixesVpnGatewayCrossAccount(rName, rBgpAsn), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsDxGatewayAssociationExists(resourceName), + testAccCheckAwsDxGatewayAssociationExists(resourceName, &ga, &gap), resource.TestCheckResourceAttrPair(resourceName, "dx_gateway_id", resourceNameDxGw, "id"), resource.TestCheckResourceAttrPair(resourceName, "associated_gateway_id", resourceNameVgw, "id"), resource.TestCheckResourceAttrSet(resourceName, "dx_gateway_association_id"), @@ -459,7 +466,7 @@ func TestAccAwsDxGatewayAssociation_allowedPrefixesVpnGatewayCrossAccount(t *tes { Config: testAccDxGatewayAssociationConfig_allowedPrefixesVpnGatewayCrossAccountUpdated(rName, rBgpAsn), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsDxGatewayAssociationExists(resourceName), + testAccCheckAwsDxGatewayAssociationExists(resourceName, &ga, &gap), resource.TestCheckResourceAttrPair(resourceName, "dx_gateway_id", resourceNameDxGw, "id"), resource.TestCheckResourceAttrPair(resourceName, "associated_gateway_id", resourceNameVgw, "id"), resource.TestCheckResourceAttrSet(resourceName, "dx_gateway_association_id"), @@ -472,6 +479,53 @@ func TestAccAwsDxGatewayAssociation_allowedPrefixesVpnGatewayCrossAccount(t *tes }) } +func TestAccAwsDxGatewayAssociation_recreateProposal(t *testing.T) { + var providers []*schema.Provider + resourceName := "aws_dx_gateway_association.test" + rName := acctest.RandomWithPrefix("tf-acc-test") + rBgpAsn := acctest.RandIntRange(64512, 65534) + var ga1, ga2 directconnect.GatewayAssociation + var gap1, gap2 directconnect.GatewayAssociationProposal + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + testAccAlternateAccountPreCheck(t) + }, + ProviderFactories: testAccProviderFactoriesAlternate(&providers), + CheckDestroy: testAccCheckAwsDxGatewayAssociationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDxGatewayAssociationConfig_basicVpnGatewayCrossAccount(rName, rBgpAsn), + Check: resource.ComposeTestCheckFunc( + testAccCheckAwsDxGatewayAssociationExists(resourceName, &ga1, &gap1), + testAccCheckAwsDxGatewayAssociationProposalDisappears(&gap1), + ), + ExpectNonEmptyPlan: true, + }, + { + Config: testAccDxGatewayAssociationConfig_basicVpnGatewayCrossAccount(rName, rBgpAsn), + Check: resource.ComposeTestCheckFunc( + testAccCheckAwsDxGatewayAssociationExists(resourceName, &ga2, &gap2), + testAccCheckAwsDxGatewayAssociationSameAssociation(&ga1, &ga2), + testAccCheckAwsDxGatewayAssociationDifferentProposal(&gap1, &gap2), + ), + }, + }, + }) +} + +func testAccAwsDxGatewayAssociationImportStateIdFunc(resourceName string) resource.ImportStateIdFunc { + return func(s *terraform.State) (string, error) { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return "", fmt.Errorf("Not Found: %s", resourceName) + } + + return fmt.Sprintf("%s/%s", rs.Primary.Attributes["dx_gateway_id"], rs.Primary.Attributes["associated_gateway_id"]), nil + } +} + func testAccCheckAwsDxGatewayAssociationDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).dxconn @@ -496,7 +550,7 @@ func testAccCheckAwsDxGatewayAssociationDestroy(s *terraform.State) error { return nil } -func testAccCheckAwsDxGatewayAssociationExists(name string) resource.TestCheckFunc { +func testAccCheckAwsDxGatewayAssociationExists(name string, ga *directconnect.GatewayAssociation, gap *directconnect.GatewayAssociationProposal) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -506,6 +560,45 @@ func testAccCheckAwsDxGatewayAssociationExists(name string) resource.TestCheckFu return fmt.Errorf("No ID is set") } + conn := testAccProvider.Meta().(*AWSClient).dxconn + resp, err := conn.DescribeDirectConnectGatewayAssociations(&directconnect.DescribeDirectConnectGatewayAssociationsInput{ + AssociationId: aws.String(rs.Primary.Attributes["dx_gateway_association_id"]), + }) + if err != nil { + return err + } + + *ga = *resp.DirectConnectGatewayAssociations[0] + + if proposalId := rs.Primary.Attributes["proposal_id"]; proposalId != "" && gap != nil { + v, err := describeDirectConnectGatewayAssociationProposal(conn, proposalId) + if err != nil { + return err + } + + *gap = *v + } + + return nil + } +} + +func testAccCheckAwsDxGatewayAssociationSameAssociation(ga1, ga2 *directconnect.GatewayAssociation) resource.TestCheckFunc { + return func(s *terraform.State) error { + if aws.StringValue(ga1.AssociationId) != aws.StringValue(ga2.AssociationId) { + return fmt.Errorf("Association IDs differ") + } + + return nil + } +} + +func testAccCheckAwsDxGatewayAssociationDifferentProposal(gap1, gap2 *directconnect.GatewayAssociationProposal) resource.TestCheckFunc { + return func(s *terraform.State) error { + if aws.StringValue(gap1.ProposalId) == aws.StringValue(gap2.ProposalId) { + return fmt.Errorf("Proposals IDs are equal") + } + return nil } } @@ -568,7 +661,9 @@ resource "aws_vpn_gateway_attachment" "test" { } func testAccDxGatewayAssociationConfigBase_vpnGatewayCrossAccount(rName string, rBgpAsn int) string { - return testAccAlternateAccountProviderConfig() + fmt.Sprintf(` + return composeConfig( + testAccAlternateAccountProviderConfig(), + fmt.Sprintf(` # Creator data "aws_caller_identity" "creator" {} @@ -598,20 +693,24 @@ resource "aws_dx_gateway" "test" { amazon_side_asn = %[2]d name = %[1]q } -`, rName, rBgpAsn) +`, rName, rBgpAsn)) } func testAccDxGatewayAssociationConfig_basicVpnGatewaySingleAccount(rName string, rBgpAsn int) string { - return testAccDxGatewayAssociationConfigBase_vpnGatewaySingleAccount(rName, rBgpAsn) + ` + return composeConfig( + testAccDxGatewayAssociationConfigBase_vpnGatewaySingleAccount(rName, rBgpAsn), + ` resource "aws_dx_gateway_association" "test" { dx_gateway_id = aws_dx_gateway.test.id associated_gateway_id = aws_vpn_gateway_attachment.test.vpn_gateway_id } -` +`) } func testAccDxGatewayAssociationConfig_basicVpnGatewayCrossAccount(rName string, rBgpAsn int) string { - return testAccDxGatewayAssociationConfigBase_vpnGatewayCrossAccount(rName, rBgpAsn) + ` + return composeConfig( + testAccDxGatewayAssociationConfigBase_vpnGatewayCrossAccount(rName, rBgpAsn), + ` # Creator resource "aws_dx_gateway_association_proposal" "test" { dx_gateway_id = aws_dx_gateway.test.id @@ -627,7 +726,7 @@ resource "aws_dx_gateway_association" "test" { dx_gateway_id = aws_dx_gateway.test.id associated_gateway_owner_account_id = data.aws_caller_identity.creator.account_id } -` +`) } func testAccDxGatewayAssociationConfig_basicTransitGatewaySingleAccount(rName string, rBgpAsn int) string { @@ -656,7 +755,9 @@ resource "aws_dx_gateway_association" "test" { } func testAccDxGatewayAssociationConfig_basicTransitGatewayCrossAccount(rName string, rBgpAsn int) string { - return testAccAlternateAccountProviderConfig() + fmt.Sprintf(` + return composeConfig( + testAccAlternateAccountProviderConfig(), + fmt.Sprintf(` # Creator data "aws_caller_identity" "creator" {} @@ -694,68 +795,54 @@ resource "aws_dx_gateway_association" "test" { dx_gateway_id = aws_dx_gateway.test.id associated_gateway_owner_account_id = data.aws_caller_identity.creator.account_id } -`, rName, rBgpAsn) +`, rName, rBgpAsn)) } -func testAccDxGatewayAssociationConfig_multiVpnGatewaysSingleAccount(rName1, rName2 string, rBgpAsn int) string { +func testAccDxGatewayAssociationConfig_multiVpnGatewaysSingleAccount(rName string, rBgpAsn int) string { return fmt.Sprintf(` resource "aws_dx_gateway" "test" { name = %[1]q - amazon_side_asn = "%[3]d" + amazon_side_asn = "%[2]d" } -resource "aws_vpc" "test1" { - cidr_block = "10.255.255.16/28" +resource "aws_vpc" "test" { + count = 2 - tags = { - Name = %[1]q - } -} + cidr_block = cidrsubnet("10.255.255.0/26", 2, count.index) -resource "aws_vpn_gateway" "test1" { tags = { Name = %[1]q } } -resource "aws_vpn_gateway_attachment" "test1" { - vpc_id = aws_vpc.test1.id - vpn_gateway_id = aws_vpn_gateway.test1.id -} - -resource "aws_dx_gateway_association" "test1" { - dx_gateway_id = aws_dx_gateway.test.id - associated_gateway_id = aws_vpn_gateway_attachment.test1.vpn_gateway_id -} - -resource "aws_vpc" "test2" { - cidr_block = "10.255.255.32/28" +resource "aws_vpn_gateway" "test" { + count = 2 tags = { - Name = %[2]q + Name = %[1]q } } -resource "aws_vpn_gateway" "test2" { - tags = { - Name = %[2]q - } -} +resource "aws_vpn_gateway_attachment" "test" { + count = 2 -resource "aws_vpn_gateway_attachment" "test2" { - vpc_id = aws_vpc.test2.id - vpn_gateway_id = aws_vpn_gateway.test2.id + vpc_id = aws_vpc.test[count.index].id + vpn_gateway_id = aws_vpn_gateway.test[count.index].id } -resource "aws_dx_gateway_association" "test2" { +resource "aws_dx_gateway_association" "test" { + count = 2 + dx_gateway_id = aws_dx_gateway.test.id - associated_gateway_id = aws_vpn_gateway_attachment.test2.vpn_gateway_id + associated_gateway_id = aws_vpn_gateway_attachment.test[count.index].vpn_gateway_id } -`, rName1, rName2, rBgpAsn) +`, rName, rBgpAsn) } func testAccDxGatewayAssociationConfig_allowedPrefixesVpnGatewaySingleAccount(rName string, rBgpAsn int) string { - return testAccDxGatewayAssociationConfigBase_vpnGatewaySingleAccount(rName, rBgpAsn) + ` + return composeConfig( + testAccDxGatewayAssociationConfigBase_vpnGatewaySingleAccount(rName, rBgpAsn), + ` resource "aws_dx_gateway_association" "test" { dx_gateway_id = aws_dx_gateway.test.id associated_gateway_id = aws_vpn_gateway_attachment.test.vpn_gateway_id @@ -765,11 +852,13 @@ resource "aws_dx_gateway_association" "test" { "10.255.255.8/30", ] } -` +`) } func testAccDxGatewayAssociationConfig_allowedPrefixesVpnGatewaySingleAccountUpdated(rName string, rBgpAsn int) string { - return testAccDxGatewayAssociationConfigBase_vpnGatewaySingleAccount(rName, rBgpAsn) + ` + return composeConfig( + testAccDxGatewayAssociationConfigBase_vpnGatewaySingleAccount(rName, rBgpAsn), + ` resource "aws_dx_gateway_association" "test" { dx_gateway_id = aws_dx_gateway.test.id associated_gateway_id = aws_vpn_gateway_attachment.test.vpn_gateway_id @@ -778,11 +867,13 @@ resource "aws_dx_gateway_association" "test" { "10.255.255.8/29", ] } -` +`) } func testAccDxGatewayAssociationConfig_allowedPrefixesVpnGatewayCrossAccount(rName string, rBgpAsn int) string { - return testAccDxGatewayAssociationConfigBase_vpnGatewayCrossAccount(rName, rBgpAsn) + ` + return composeConfig( + testAccDxGatewayAssociationConfigBase_vpnGatewayCrossAccount(rName, rBgpAsn), + ` # Creator resource "aws_dx_gateway_association_proposal" "test" { dx_gateway_id = aws_dx_gateway.test.id @@ -807,11 +898,13 @@ resource "aws_dx_gateway_association" "test" { "10.255.255.8/29", ] } -` +`) } func testAccDxGatewayAssociationConfig_allowedPrefixesVpnGatewayCrossAccountUpdated(rName string, rBgpAsn int) string { - return testAccDxGatewayAssociationConfigBase_vpnGatewayCrossAccount(rName, rBgpAsn) + ` + return composeConfig( + testAccDxGatewayAssociationConfigBase_vpnGatewayCrossAccount(rName, rBgpAsn), + ` # Creator resource "aws_dx_gateway_association_proposal" "test" { dx_gateway_id = aws_dx_gateway.test.id @@ -832,5 +925,5 @@ resource "aws_dx_gateway_association" "test" { "10.255.255.8/30", ] } -` +`) } diff --git a/aws/resource_aws_dx_gateway_test.go b/aws/resource_aws_dx_gateway_test.go index 61e4c8ce934..54462b8e1f9 100644 --- a/aws/resource_aws_dx_gateway_test.go +++ b/aws/resource_aws_dx_gateway_test.go @@ -139,8 +139,7 @@ func TestAccAwsDxGateway_basic(t *testing.T) { } func TestAccAwsDxGateway_complex(t *testing.T) { - rName1 := fmt.Sprintf("terraform-testacc-dxgwassoc-%d", acctest.RandInt()) - rName2 := fmt.Sprintf("terraform-testacc-dxgwassoc-%d", acctest.RandInt()) + rName := acctest.RandomWithPrefix("tf-acc-test") rBgpAsn := acctest.RandIntRange(64512, 65534) resourceName := "aws_dx_gateway.test" @@ -150,7 +149,7 @@ func TestAccAwsDxGateway_complex(t *testing.T) { CheckDestroy: testAccCheckAwsDxGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccDxGatewayAssociationConfig_multiVpnGatewaysSingleAccount(rName1, rName2, rBgpAsn), + Config: testAccDxGatewayAssociationConfig_multiVpnGatewaysSingleAccount(rName, rBgpAsn), Check: resource.ComposeTestCheckFunc( testAccCheckAwsDxGatewayExists(resourceName), testAccCheckResourceAttrAccountID(resourceName, "owner_account_id"), diff --git a/aws/resource_aws_ec2_transit_gateway.go b/aws/resource_aws_ec2_transit_gateway.go index 77fc51c2cc7..681a7d558bd 100644 --- a/aws/resource_aws_ec2_transit_gateway.go +++ b/aws/resource_aws_ec2_transit_gateway.go @@ -266,7 +266,7 @@ func resourceAwsEc2TransitGatewayDelete(d *schema.ResourceData, meta interface{} } log.Printf("[DEBUG] Deleting EC2 Transit Gateway (%s): %s", d.Id(), input) - err := resource.Retry(2*time.Minute, func() *resource.RetryError { + err := resource.Retry(5*time.Minute, func() *resource.RetryError { _, err := conn.DeleteTransitGateway(input) if isAWSErr(err, "IncorrectState", "has non-deleted Transit Gateway Attachments") {