Skip to content

Commit

Permalink
Add Direct Connect gateway association allow prefix acceptance tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Apr 21, 2019
1 parent 191e73f commit c1021a3
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 5 deletions.
5 changes: 3 additions & 2 deletions aws/resource_aws_dx_gateway_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func resourceAwsDxGatewayAssociation() *schema.Resource {
"allowed_prefixes": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

Expand All @@ -54,7 +55,7 @@ func resourceAwsDxGatewayAssociation() *schema.Resource {
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(15 * time.Minute),
Update: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(15 * time.Minute),
},
}
}
Expand Down Expand Up @@ -91,7 +92,7 @@ func resourceAwsDxGatewayAssociationCreate(d *schema.ResourceData, meta interfac
return fmt.Errorf("error waiting for Direct Connect gateway association (%s) to become available: %s", d.Id(), err)
}

return nil
return resourceAwsDxGatewayAssociationRead(d, meta)
}

func resourceAwsDxGatewayAssociationRead(d *schema.ResourceData, meta interface{}) error {
Expand Down
120 changes: 118 additions & 2 deletions aws/resource_aws_dx_gateway_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,14 @@ func TestAccAwsDxGatewayAssociation_basic(t *testing.T) {
CheckDestroy: testAccCheckAwsDxGatewayAssociationDestroy,
Steps: []resource.TestStep{
{
Config: testAccDxGatewayAssociationConfig(rName, rBgpAsn),
Config: testAccDxGatewayAssociationConfig_basic(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.TestCheckResourceAttr(resourceName, "allowed_prefixes.#", "1"),
resource.TestCheckResourceAttr(resourceName, "allowed_prefixes.1216997074", "10.255.255.0/28"),
),
},
{
Expand Down Expand Up @@ -155,6 +158,48 @@ func TestAccAwsDxGatewayAssociation_multiVgws(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsDxGatewayAssociationExists(resourceName1),
testAccCheckAwsDxGatewayAssociationExists(resourceName2),
resource.TestCheckResourceAttrSet(resourceName1, "dx_gateway_association_id"),
resource.TestCheckResourceAttr(resourceName1, "allowed_prefixes.#", "1"),
resource.TestCheckResourceAttr(resourceName1, "allowed_prefixes.704201654", "10.255.255.16/28"),
resource.TestCheckResourceAttrSet(resourceName2, "dx_gateway_association_id"),
resource.TestCheckResourceAttr(resourceName2, "allowed_prefixes.#", "1"),
resource.TestCheckResourceAttr(resourceName2, "allowed_prefixes.2444313725", "10.255.255.32/28"),
),
},
},
})
}

func TestAccAwsDxGatewayAssociation_allowedPrefixes(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_allowedPrefixes(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.TestCheckResourceAttr(resourceName, "allowed_prefixes.#", "2"),
resource.TestCheckResourceAttr(resourceName, "allowed_prefixes.2173830893", "10.255.255.0/30"),
resource.TestCheckResourceAttr(resourceName, "allowed_prefixes.2984398124", "10.255.255.8/30"),
),
},
{
Config: testAccDxGatewayAssociationConfig_allowedPrefixesUpdated(rName, rBgpAsn),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsDxGatewayAssociationExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "allowed_prefixes.#", "1"),
resource.TestCheckResourceAttr(resourceName, "allowed_prefixes.1642241106", "10.255.255.8/29"),
),
},
},
Expand Down Expand Up @@ -195,7 +240,7 @@ func testAccCheckAwsDxGatewayAssociationExists(name string) resource.TestCheckFu
}
}

func testAccDxGatewayAssociationConfig(rName string, rBgpAsn int) string {
func testAccDxGatewayAssociationConfig_basic(rName string, rBgpAsn int) string {
return fmt.Sprintf(`
resource "aws_dx_gateway" "test" {
name = %[1]q
Expand Down Expand Up @@ -281,3 +326,74 @@ resource "aws_dx_gateway_association" "test2" {
}
`, rName1, rName2, rBgpAsn)
}

func testAccDxGatewayAssociationConfig_allowedPrefixes(rName string, rBgpAsn int) string {
return fmt.Sprintf(`
resource "aws_dx_gateway" "test" {
name = %[1]q
amazon_side_asn = "%[2]d"
}
resource "aws_vpc" "test" {
cidr_block = "10.255.255.0/28"
tags = {
Name = %[1]q
}
}
resource "aws_vpn_gateway" "test" {
tags = {
Name = %[1]q
}
}
resource "aws_vpn_gateway_attachment" "test" {
vpc_id = "${aws_vpc.test.id}"
vpn_gateway_id = "${aws_vpn_gateway.test.id}"
}
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}"
allowed_prefixes = [
"10.255.255.0/30",
"10.255.255.8/30",
]
}
`, rName, rBgpAsn)
}

func testAccDxGatewayAssociationConfig_allowedPrefixesUpdated(rName string, rBgpAsn int) string {
return fmt.Sprintf(`
resource "aws_dx_gateway" "test" {
name = %[1]q
amazon_side_asn = "%[2]d"
}
resource "aws_vpc" "test" {
cidr_block = "10.255.255.0/28"
tags = {
Name = %[1]q
}
}
resource "aws_vpn_gateway" "test" {
tags = {
Name = %[1]q
}
}
resource "aws_vpn_gateway_attachment" "test" {
vpc_id = "${aws_vpc.test.id}"
vpn_gateway_id = "${aws_vpn_gateway.test.id}"
}
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}"
allowed_prefixes = [
"10.255.255.8/29",
]
}
`, rName, rBgpAsn)
}
2 changes: 1 addition & 1 deletion website/docs/r/dx_gateway_association.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ In addition to all arguments above, the following attributes are exported:

- `create` - (Default `15 minutes`) Used for creating the association
- `update` - (Default `10 minutes`) Used for updating the association
- `delete` - (Default `10 minutes`) Used for destroying the association
- `delete` - (Default `15 minutes`) Used for destroying the association

## Import

Expand Down

0 comments on commit c1021a3

Please sign in to comment.