Skip to content

Commit

Permalink
service/directconnect: Remove vpn_gateway_id arguments
Browse files Browse the repository at this point in the history
Reference: #13398

Changes:

```
* resource/aws_dx_gateway_association: Remove `vpn_gateway_id` argument
* resource/aws_dx_gateway_association_proposal: Remove `vpn_gateway_id` argument
```

Output from acceptance testing:

```
--- PASS: TestAccAwsDxGatewayAssociation_basicTransitGatewaySingleAccount (2063.56s)
--- PASS: TestAccAwsDxGatewayAssociation_basicTransitGatewayCrossAccount (2556.75s)
--- PASS: TestAccAwsDxGatewayAssociation_multiVpnGatewaysSingleAccount (2668.06s)
--- PASS: TestAccAwsDxGatewayAssociation_basicVpnGatewaySingleAccount (2674.09s)
--- PASS: TestAccAwsDxGatewayAssociation_basicVpnGatewayCrossAccount (2677.20s)
--- PASS: TestAccAwsDxGatewayAssociation_allowedPrefixesVpnGatewaySingleAccount (3612.36s)
--- PASS: TestAccAwsDxGatewayAssociation_allowedPrefixesVpnGatewayCrossAccount (3856.32s)

--- PASS: TestAccAwsDxGatewayAssociationProposal_basicVpnGateway (88.64s)
--- PASS: TestAccAwsDxGatewayAssociationProposal_disappears (96.50s)
--- PASS: TestAccAwsDxGatewayAssociationProposal_AllowedPrefixes (121.18s)
--- PASS: TestAccAwsDxGatewayAssociationProposal_basicTransitGateway (182.42s)
```
  • Loading branch information
bflad committed Jul 22, 2020
1 parent b7d1f63 commit 1af482a
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 160 deletions.
43 changes: 9 additions & 34 deletions aws/resource_aws_dx_gateway_association.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package aws

import (
"errors"
"fmt"
"log"
"strings"
Expand Down Expand Up @@ -49,7 +48,7 @@ func resourceAwsDxGatewayAssociation() *schema.Resource {
Optional: true,
Computed: true,
ForceNew: true,
ConflictsWith: []string{"associated_gateway_owner_account_id", "proposal_id", "vpn_gateway_id"},
ConflictsWith: []string{"associated_gateway_owner_account_id", "proposal_id"},
},

"associated_gateway_owner_account_id": {
Expand All @@ -58,7 +57,7 @@ func resourceAwsDxGatewayAssociation() *schema.Resource {
Computed: true,
ForceNew: true,
ValidateFunc: validateAwsAccountId,
ConflictsWith: []string{"associated_gateway_id", "vpn_gateway_id"},
ConflictsWith: []string{"associated_gateway_id"},
},

"associated_gateway_type": {
Expand Down Expand Up @@ -86,15 +85,7 @@ func resourceAwsDxGatewayAssociation() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"associated_gateway_id", "vpn_gateway_id"},
},

"vpn_gateway_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"associated_gateway_id", "associated_gateway_owner_account_id", "proposal_id"},
Deprecated: "use 'associated_gateway_id' argument instead",
ConflictsWith: []string{"associated_gateway_id"},
},
},

Expand All @@ -111,7 +102,6 @@ func resourceAwsDxGatewayAssociationCreate(d *schema.ResourceData, meta interfac

dxgwId := d.Get("dx_gateway_id").(string)
gwIdRaw, gwIdOk := d.GetOk("associated_gateway_id")
vgwIdRaw, vgwIdOk := d.GetOk("vpn_gateway_id")
gwAcctIdRaw, gwAcctIdOk := d.GetOk("associated_gateway_owner_account_id")
proposalIdRaw, proposalIdOk := d.GetOk("proposal_id")

Expand All @@ -120,8 +110,8 @@ func resourceAwsDxGatewayAssociationCreate(d *schema.ResourceData, meta interfac
if !(gwAcctIdOk && proposalIdOk) {
return fmt.Errorf("associated_gateway_owner_account_id and proposal_id must be configured")
}
} else if !(gwIdOk || vgwIdOk) {
return fmt.Errorf("either associated_gateway_owner_account_id and proposal_id or one of associated_gateway_id or vpn_gateway_id must be configured")
} else if !gwIdOk {
return fmt.Errorf("either associated_gateway_owner_account_id and proposal_id, or associated_gateway_id, must be configured")
}

associationId := ""
Expand All @@ -143,17 +133,12 @@ func resourceAwsDxGatewayAssociationCreate(d *schema.ResourceData, meta interfac
associationId = aws.StringValue(resp.DirectConnectGatewayAssociation.AssociationId)
d.SetId(dxGatewayAssociationId(dxgwId, aws.StringValue(resp.DirectConnectGatewayAssociation.AssociatedGateway.Id)))
} else {
gwId := gwIdRaw.(string)

req := &directconnect.CreateDirectConnectGatewayAssociationInput{
AddAllowedPrefixesToDirectConnectGateway: expandDxRouteFilterPrefixes(d.Get("allowed_prefixes").(*schema.Set)),
DirectConnectGatewayId: aws.String(dxgwId),
}
gwId := ""
if gwIdOk {
gwId = gwIdRaw.(string)
req.GatewayId = aws.String(gwId)
} else {
gwId = vgwIdRaw.(string)
req.VirtualGatewayId = aws.String(gwId)
GatewayId: aws.String(gwId),
}

log.Printf("[DEBUG] Creating Direct Connect gateway association: %#v", req)
Expand Down Expand Up @@ -196,11 +181,7 @@ func resourceAwsDxGatewayAssociationRead(d *schema.ResourceData, meta interface{
return fmt.Errorf("error setting allowed_prefixes: %s", err)
}

if _, ok := d.GetOk("vpn_gateway_id"); ok {
d.Set("vpn_gateway_id", assoc.VirtualGatewayId)
} else {
d.Set("associated_gateway_id", assoc.AssociatedGateway.Id)
}
d.Set("associated_gateway_id", assoc.AssociatedGateway.Id)
d.Set("associated_gateway_owner_account_id", assoc.AssociatedGateway.OwnerAccount)
d.Set("associated_gateway_type", assoc.AssociatedGateway.Type)
d.Set("dx_gateway_association_id", assoc.AssociationId)
Expand All @@ -213,12 +194,6 @@ func resourceAwsDxGatewayAssociationRead(d *schema.ResourceData, meta interface{
func resourceAwsDxGatewayAssociationUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).dxconn

_, gwIdOk := d.GetOk("associated_gateway_id")
_, vgwIdOk := d.GetOk("vpn_gateway_id")
if !gwIdOk && !vgwIdOk {
return errors.New("one of associated_gateway_id or vpn_gateway_id must be configured")
}

if d.HasChange("allowed_prefixes") {
associationId := d.Get("dx_gateway_association_id").(string)

Expand Down
1 change: 0 additions & 1 deletion aws/resource_aws_dx_gateway_association_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func resourceAwsDxGatewayAssociationResourceV0() *schema.Resource {
Optional: true,
ForceNew: true,
ConflictsWith: []string{"associated_gateway_id", "associated_gateway_owner_account_id", "proposal_id"},
Deprecated: "use 'associated_gateway_id' argument instead",
},
},
}
Expand Down
33 changes: 5 additions & 28 deletions aws/resource_aws_dx_gateway_association_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ func resourceAwsDxGatewayAssociationProposal() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
},
"associated_gateway_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"vpn_gateway_id"},
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"associated_gateway_owner_account_id": {
Type: schema.TypeString,
Expand All @@ -67,13 +66,6 @@ func resourceAwsDxGatewayAssociationProposal() *schema.Resource {
ForceNew: true,
ValidateFunc: validateAwsAccountId,
},
"vpn_gateway_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"associated_gateway_id"},
Deprecated: "use 'associated_gateway_id' argument instead",
},
},
}
}
Expand All @@ -86,20 +78,9 @@ func resourceAwsDxGatewayAssociationProposalCreate(d *schema.ResourceData, meta
AddAllowedPrefixesToDirectConnectGateway: allowedPrefixes,
DirectConnectGatewayId: aws.String(d.Get("dx_gateway_id").(string)),
DirectConnectGatewayOwnerAccount: aws.String(d.Get("dx_gateway_owner_account_id").(string)),
}
var gwID string
if v, ok := d.GetOk("vpn_gateway_id"); ok {
gwID = v.(string)
} else if v, ok := d.GetOk("associated_gateway_id"); ok {
gwID = v.(string)
GatewayId: aws.String(d.Get("associated_gateway_id").(string)),
}

if gwID == "" {
return fmt.Errorf("gateway id not provided, one of associated_gateway_id or vpn_gateway_id must be configured")
}

input.GatewayId = aws.String(gwID)

log.Printf("[DEBUG] Creating Direct Connect Gateway Association Proposal: %s", input)
output, err := conn.CreateDirectConnectGatewayAssociationProposal(input)

Expand Down Expand Up @@ -141,11 +122,7 @@ func resourceAwsDxGatewayAssociationProposalRead(d *schema.ResourceData, meta in
return fmt.Errorf("error setting allowed_prefixes: %s", err)
}

if _, ok := d.GetOk("vpn_gateway_id"); ok {
d.Set("vpn_gateway_id", aws.StringValue(proposal.AssociatedGateway.Id))
} else {
d.Set("associated_gateway_id", aws.StringValue(proposal.AssociatedGateway.Id))
}
d.Set("associated_gateway_id", aws.StringValue(proposal.AssociatedGateway.Id))
d.Set("associated_gateway_owner_account_id", proposal.AssociatedGateway.OwnerAccount)
d.Set("associated_gateway_type", proposal.AssociatedGateway.Type)
d.Set("dx_gateway_id", aws.StringValue(proposal.DirectConnectGatewayId))
Expand Down
45 changes: 0 additions & 45 deletions aws/resource_aws_dx_gateway_association_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,39 +78,6 @@ func testSweepDirectConnectGatewayAssociationProposals(region string) error {
return nil
}

func TestAccAwsDxGatewayAssociationProposal_VpnGatewayId(t *testing.T) {
var proposal1 directconnect.GatewayAssociationProposal
var providers []*schema.Provider
rBgpAsn := randIntRange(64512, 65534)
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_dx_gateway_association_proposal.test"
resourceNameDxGw := "aws_dx_gateway.test"
resourceNameVgw := "aws_vpn_gateway.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccAlternateAccountPreCheck(t)
},
ProviderFactories: testAccProviderFactories(&providers),
CheckDestroy: testAccCheckAwsDxGatewayAssociationProposalDestroy,
Steps: []resource.TestStep{
{
Config: testAccDxGatewayAssociationProposalConfig_vpnGatewayId(rName, rBgpAsn),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsDxGatewayAssociationProposalExists(resourceName, &proposal1),
resource.TestCheckResourceAttrPair(resourceName, "dx_gateway_id", resourceNameDxGw, "id"),
resource.TestCheckResourceAttrPair(resourceName, "vpn_gateway_id", resourceNameVgw, "id"),
resource.TestCheckNoResourceAttr(resourceName, "associated_gateway_id"),
testAccCheckResourceAttrAccountID(resourceName, "associated_gateway_owner_account_id"),
resource.TestCheckResourceAttr(resourceName, "associated_gateway_type", "virtualPrivateGateway"),
resource.TestCheckResourceAttr(resourceName, "allowed_prefixes.#", "1"),
),
},
},
})
}

func TestAccAwsDxGatewayAssociationProposal_basicVpnGateway(t *testing.T) {
var proposal1 directconnect.GatewayAssociationProposal
var providers []*schema.Provider
Expand All @@ -134,7 +101,6 @@ func TestAccAwsDxGatewayAssociationProposal_basicVpnGateway(t *testing.T) {
testAccCheckAwsDxGatewayAssociationProposalExists(resourceName, &proposal1),
resource.TestCheckResourceAttrPair(resourceName, "dx_gateway_id", resourceNameDxGw, "id"),
resource.TestCheckResourceAttrPair(resourceName, "associated_gateway_id", resourceNameVgw, "id"),
resource.TestCheckNoResourceAttr(resourceName, "vpn_gateway_id"),
testAccCheckResourceAttrAccountID(resourceName, "associated_gateway_owner_account_id"),
resource.TestCheckResourceAttr(resourceName, "associated_gateway_type", "virtualPrivateGateway"),
resource.TestCheckResourceAttr(resourceName, "allowed_prefixes.#", "1"),
Expand Down Expand Up @@ -173,7 +139,6 @@ func TestAccAwsDxGatewayAssociationProposal_basicTransitGateway(t *testing.T) {
testAccCheckAwsDxGatewayAssociationProposalExists(resourceName, &proposal1),
resource.TestCheckResourceAttrPair(resourceName, "dx_gateway_id", resourceNameDxGw, "id"),
resource.TestCheckResourceAttrPair(resourceName, "associated_gateway_id", resourceNameTgw, "id"),
resource.TestCheckNoResourceAttr(resourceName, "vpn_gateway_id"),
testAccCheckResourceAttrAccountID(resourceName, "associated_gateway_owner_account_id"),
resource.TestCheckResourceAttr(resourceName, "associated_gateway_type", "transitGateway"),
resource.TestCheckResourceAttr(resourceName, "allowed_prefixes.#", "2"),
Expand Down Expand Up @@ -358,16 +323,6 @@ resource "aws_vpn_gateway" "test" {
`, rName, rBgpAsn)
}

func testAccDxGatewayAssociationProposalConfig_vpnGatewayId(rName string, rBgpAsn int) string {
return testAccDxGatewayAssociationProposalConfigBase_vpnGateway(rName, rBgpAsn) + `
resource "aws_dx_gateway_association_proposal" "test" {
dx_gateway_id = "${aws_dx_gateway.test.id}"
dx_gateway_owner_account_id = "${aws_dx_gateway.test.owner_account_id}"
vpn_gateway_id = "${aws_vpn_gateway.test.id}"
}
`
}

func testAccDxGatewayAssociationProposalConfig_basicVpnGateway(rName string, rBgpAsn int) string {
return testAccDxGatewayAssociationProposalConfigBase_vpnGateway(rName, rBgpAsn) + `
resource "aws_dx_gateway_association_proposal" "test" {
Expand Down
45 changes: 0 additions & 45 deletions aws/resource_aws_dx_gateway_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,38 +182,6 @@ func testSweepDirectConnectGatewayAssociations(region string) error {
return nil
}

func TestAccAwsDxGatewayAssociation_deprecatedSingleAccount(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())
rBgpAsn := randIntRange(64512, 65534)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsDxGatewayAssociationDestroy,
Steps: []resource.TestStep{
{
Config: testAccDxGatewayAssociationConfig_deprecatedSingleAccount(rName, rBgpAsn),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsDxGatewayAssociationExists(resourceName),
resource.TestCheckResourceAttrPair(resourceName, "dx_gateway_id", resourceNameDxGw, "id"),
resource.TestCheckResourceAttrPair(resourceName, "vpn_gateway_id", resourceNameVgw, "id"),
resource.TestCheckResourceAttrSet(resourceName, "dx_gateway_association_id"),
resource.TestCheckNoResourceAttr(resourceName, "associated_gateway_id"),
resource.TestCheckResourceAttr(resourceName, "associated_gateway_type", "virtualPrivateGateway"),
testAccCheckResourceAttrAccountID(resourceName, "associated_gateway_owner_account_id"),
testAccCheckResourceAttrAccountID(resourceName, "dx_gateway_owner_account_id"),
resource.TestCheckResourceAttr(resourceName, "allowed_prefixes.#", "1"),
tfawsresource.TestCheckTypeSetElemAttr(resourceName, "allowed_prefixes.*", "10.255.255.0/28"),
testAccCheckAwsDxGatewayAssociationStateUpgradeV0(resourceName),
),
},
},
})
}

func TestAccAwsDxGatewayAssociation_basicVpnGatewaySingleAccount(t *testing.T) {
resourceName := "aws_dx_gateway_association.test"
resourceNameDxGw := "aws_dx_gateway.test"
Expand All @@ -233,7 +201,6 @@ func TestAccAwsDxGatewayAssociation_basicVpnGatewaySingleAccount(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName, "dx_gateway_id", resourceNameDxGw, "id"),
resource.TestCheckResourceAttrPair(resourceName, "associated_gateway_id", resourceNameVgw, "id"),
resource.TestCheckResourceAttrSet(resourceName, "dx_gateway_association_id"),
resource.TestCheckNoResourceAttr(resourceName, "vpn_gateway_id"),
resource.TestCheckResourceAttr(resourceName, "associated_gateway_type", "virtualPrivateGateway"),
testAccCheckResourceAttrAccountID(resourceName, "associated_gateway_owner_account_id"),
testAccCheckResourceAttrAccountID(resourceName, "dx_gateway_owner_account_id"),
Expand Down Expand Up @@ -281,7 +248,6 @@ func TestAccAwsDxGatewayAssociation_basicVpnGatewayCrossAccount(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName, "dx_gateway_id", resourceNameDxGw, "id"),
resource.TestCheckResourceAttrPair(resourceName, "associated_gateway_id", resourceNameVgw, "id"),
resource.TestCheckResourceAttrSet(resourceName, "dx_gateway_association_id"),
resource.TestCheckNoResourceAttr(resourceName, "vpn_gateway_id"),
resource.TestCheckResourceAttr(resourceName, "associated_gateway_type", "virtualPrivateGateway"),
testAccCheckResourceAttrAccountID(resourceName, "associated_gateway_owner_account_id"),
// dx_gateway_owner_account_id is the "aws.alternate" provider's account ID.
Expand Down Expand Up @@ -313,7 +279,6 @@ func TestAccAwsDxGatewayAssociation_basicTransitGatewaySingleAccount(t *testing.
resource.TestCheckResourceAttrPair(resourceName, "dx_gateway_id", resourceNameDxGw, "id"),
resource.TestCheckResourceAttrPair(resourceName, "associated_gateway_id", resourceNameTgw, "id"),
resource.TestCheckResourceAttrSet(resourceName, "dx_gateway_association_id"),
resource.TestCheckNoResourceAttr(resourceName, "vpn_gateway_id"),
resource.TestCheckResourceAttr(resourceName, "associated_gateway_type", "transitGateway"),
testAccCheckResourceAttrAccountID(resourceName, "associated_gateway_owner_account_id"),
testAccCheckResourceAttrAccountID(resourceName, "dx_gateway_owner_account_id"),
Expand Down Expand Up @@ -362,7 +327,6 @@ func TestAccAwsDxGatewayAssociation_basicTransitGatewayCrossAccount(t *testing.T
resource.TestCheckResourceAttrPair(resourceName, "dx_gateway_id", resourceNameDxGw, "id"),
resource.TestCheckResourceAttrPair(resourceName, "associated_gateway_id", resourceNameTgw, "id"),
resource.TestCheckResourceAttrSet(resourceName, "dx_gateway_association_id"),
resource.TestCheckNoResourceAttr(resourceName, "vpn_gateway_id"),
resource.TestCheckResourceAttr(resourceName, "associated_gateway_type", "transitGateway"),
testAccCheckResourceAttrAccountID(resourceName, "associated_gateway_owner_account_id"),
// dx_gateway_owner_account_id is the "aws.alternate" provider's account ID.
Expand Down Expand Up @@ -615,15 +579,6 @@ resource "aws_dx_gateway" "test" {
`, rName, rBgpAsn)
}

func testAccDxGatewayAssociationConfig_deprecatedSingleAccount(rName string, rBgpAsn int) string {
return testAccDxGatewayAssociationConfigBase_vpnGatewaySingleAccount(rName, rBgpAsn) + `
resource "aws_dx_gateway_association" "test" {
dx_gateway_id = "${aws_dx_gateway.test.id}"
vpn_gateway_id = "${aws_vpn_gateway_attachment.test.vpn_gateway_id}"
}
`
}

func testAccDxGatewayAssociationConfig_basicVpnGatewaySingleAccount(rName string, rBgpAsn int) string {
return testAccDxGatewayAssociationConfigBase_vpnGatewaySingleAccount(rName, rBgpAsn) + `
resource "aws_dx_gateway_association" "test" {
Expand Down
Loading

0 comments on commit 1af482a

Please sign in to comment.