From 5298e481ff5f93a5f9866cee16fe6349842eb81d Mon Sep 17 00:00:00 2001 From: "Aaron J. Smith" Date: Fri, 12 Oct 2018 22:47:26 -0500 Subject: [PATCH 01/14] resource/aws_dx_private_virtual_interface: Update resource to support MTU param --- aws/resource_aws_dx_private_virtual_interface.go | 11 +++++++++++ aws/resource_aws_dx_private_virtual_interface_test.go | 3 +++ .../docs/r/dx_private_virtual_interface.html.markdown | 1 + 3 files changed, 15 insertions(+) diff --git a/aws/resource_aws_dx_private_virtual_interface.go b/aws/resource_aws_dx_private_virtual_interface.go index cd92f28b626..e60d237bf04 100644 --- a/aws/resource_aws_dx_private_virtual_interface.go +++ b/aws/resource_aws_dx_private_virtual_interface.go @@ -84,6 +84,12 @@ func resourceAwsDxPrivateVirtualInterface() *schema.Resource { Computed: true, ForceNew: true, }, + "mtu": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, "tags": tagsSchema(), }, @@ -111,6 +117,7 @@ func resourceAwsDxPrivateVirtualInterfaceCreate(d *schema.ResourceData, meta int Vlan: aws.Int64(int64(d.Get("vlan").(int))), Asn: aws.Int64(int64(d.Get("bgp_asn").(int))), AddressFamily: aws.String(d.Get("address_family").(string)), + Mtu: aws.Int64(int64(d.Get("mtu").(int))), }, } if vgwOk && vgwIdRaw.(string) != "" { @@ -128,6 +135,9 @@ func resourceAwsDxPrivateVirtualInterfaceCreate(d *schema.ResourceData, meta int if v, ok := d.GetOk("amazon_address"); ok && v.(string) != "" { req.NewPrivateVirtualInterface.AmazonAddress = aws.String(v.(string)) } + if v, ok := d.GetOk("mtu"); ok && v.(int) != 0 { + req.NewPrivateVirtualInterface.Mtu = aws.Int64(v.(int64)) + } log.Printf("[DEBUG] Creating Direct Connect private virtual interface: %#v", req) resp, err := conn.CreatePrivateVirtualInterface(req) @@ -175,6 +185,7 @@ func resourceAwsDxPrivateVirtualInterfaceRead(d *schema.ResourceData, meta inter d.Set("amazon_address", vif.AmazonAddress) d.Set("vpn_gateway_id", vif.VirtualGatewayId) d.Set("dx_gateway_id", vif.DirectConnectGatewayId) + d.Set("mtu", vif.Mtu) if err := getTagsDX(conn, d, d.Get("arn").(string)); err != nil { return err } diff --git a/aws/resource_aws_dx_private_virtual_interface_test.go b/aws/resource_aws_dx_private_virtual_interface_test.go index cb5b9bee73b..caa22884544 100644 --- a/aws/resource_aws_dx_private_virtual_interface_test.go +++ b/aws/resource_aws_dx_private_virtual_interface_test.go @@ -131,6 +131,7 @@ resource "aws_dx_private_virtual_interface" "foo" { vlan = 4094 address_family = "ipv4" bgp_asn = %d + mtu = 9100 } `, n, cid, n, bgpAsn) } @@ -151,6 +152,7 @@ resource "aws_dx_private_virtual_interface" "foo" { vlan = 4094 address_family = "ipv4" bgp_asn = %d + mtu = 9100 tags { Environment = "test" @@ -174,6 +176,7 @@ resource "aws_dx_private_virtual_interface" "foo" { vlan = 4094 address_family = "ipv4" bgp_asn = %d + mtu = 9100 } `, n, amzAsn, cid, n, bgpAsn) } diff --git a/website/docs/r/dx_private_virtual_interface.html.markdown b/website/docs/r/dx_private_virtual_interface.html.markdown index 2503eb17fa0..db11fb2d745 100644 --- a/website/docs/r/dx_private_virtual_interface.html.markdown +++ b/website/docs/r/dx_private_virtual_interface.html.markdown @@ -33,6 +33,7 @@ The following arguments are supported: * `name` - (Required) The name for the virtual interface. * `vlan` - (Required) The VLAN ID. * `amazon_address` - (Optional) The IPv4 CIDR address to use to send traffic to Amazon. Required for IPv4 BGP peers. +* `mtu` - (Optional) The maximum transmission unit (MTU) is the size, in bytes, of the largest permissible packet that can be passed over the connection. The MTU of a virtual private interface can be either 1500 or 9001 (jumbo frames). Default is 1500. * `bgp_auth_key` - (Optional) The authentication key for BGP configuration. * `customer_address` - (Optional) The IPv4 CIDR destination address to which Amazon should send traffic. Required for IPv4 BGP peers. * `dx_gateway_id` - (Optional) The ID of the Direct Connect gateway to which to connect the virtual interface. From d549990aeb63d709f8de7c9caca4fe621750e366 Mon Sep 17 00:00:00 2001 From: "Aaron J. Smith" Date: Fri, 12 Oct 2018 23:31:16 -0500 Subject: [PATCH 02/14] fixing mtu int handling --- aws/resource_aws_dx_private_virtual_interface.go | 4 ++-- aws/resource_aws_dx_private_virtual_interface_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/aws/resource_aws_dx_private_virtual_interface.go b/aws/resource_aws_dx_private_virtual_interface.go index e60d237bf04..d20a91eebb5 100644 --- a/aws/resource_aws_dx_private_virtual_interface.go +++ b/aws/resource_aws_dx_private_virtual_interface.go @@ -85,7 +85,7 @@ func resourceAwsDxPrivateVirtualInterface() *schema.Resource { ForceNew: true, }, "mtu": { - Type: schema.TypeString, + Type: schema.TypeInt, Optional: true, Computed: true, ForceNew: true, @@ -136,7 +136,7 @@ func resourceAwsDxPrivateVirtualInterfaceCreate(d *schema.ResourceData, meta int req.NewPrivateVirtualInterface.AmazonAddress = aws.String(v.(string)) } if v, ok := d.GetOk("mtu"); ok && v.(int) != 0 { - req.NewPrivateVirtualInterface.Mtu = aws.Int64(v.(int64)) + req.NewPrivateVirtualInterface.Mtu = aws.Int64(int64(v.(int))) } log.Printf("[DEBUG] Creating Direct Connect private virtual interface: %#v", req) diff --git a/aws/resource_aws_dx_private_virtual_interface_test.go b/aws/resource_aws_dx_private_virtual_interface_test.go index caa22884544..85e29cc8614 100644 --- a/aws/resource_aws_dx_private_virtual_interface_test.go +++ b/aws/resource_aws_dx_private_virtual_interface_test.go @@ -131,7 +131,7 @@ resource "aws_dx_private_virtual_interface" "foo" { vlan = 4094 address_family = "ipv4" bgp_asn = %d - mtu = 9100 + mtu = 9001 } `, n, cid, n, bgpAsn) } @@ -152,7 +152,7 @@ resource "aws_dx_private_virtual_interface" "foo" { vlan = 4094 address_family = "ipv4" bgp_asn = %d - mtu = 9100 + mtu = 9001 tags { Environment = "test" @@ -176,7 +176,7 @@ resource "aws_dx_private_virtual_interface" "foo" { vlan = 4094 address_family = "ipv4" bgp_asn = %d - mtu = 9100 + mtu = 9001 } `, n, amzAsn, cid, n, bgpAsn) } From b5f9c8244f94600d1ca4ccf7aecdf2f13e45aff5 Mon Sep 17 00:00:00 2001 From: "Aaron J. Smith" Date: Sat, 13 Oct 2018 00:21:15 -0500 Subject: [PATCH 03/14] exporting value of jumbo frames param --- aws/resource_aws_dx_private_virtual_interface.go | 5 +++++ website/docs/r/dx_private_virtual_interface.html.markdown | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/aws/resource_aws_dx_private_virtual_interface.go b/aws/resource_aws_dx_private_virtual_interface.go index d20a91eebb5..6269af6fb50 100644 --- a/aws/resource_aws_dx_private_virtual_interface.go +++ b/aws/resource_aws_dx_private_virtual_interface.go @@ -90,6 +90,10 @@ func resourceAwsDxPrivateVirtualInterface() *schema.Resource { Computed: true, ForceNew: true, }, + "jumbo_frame_enabled": { + Type: schema.TypeBool, + Computed: true, + }, "tags": tagsSchema(), }, @@ -186,6 +190,7 @@ func resourceAwsDxPrivateVirtualInterfaceRead(d *schema.ResourceData, meta inter d.Set("vpn_gateway_id", vif.VirtualGatewayId) d.Set("dx_gateway_id", vif.DirectConnectGatewayId) d.Set("mtu", vif.Mtu) + d.Set("jumbo_frame_capable", vif.JumboFrameCapable) if err := getTagsDX(conn, d, d.Get("arn").(string)); err != nil { return err } diff --git a/website/docs/r/dx_private_virtual_interface.html.markdown b/website/docs/r/dx_private_virtual_interface.html.markdown index db11fb2d745..68a84721244 100644 --- a/website/docs/r/dx_private_virtual_interface.html.markdown +++ b/website/docs/r/dx_private_virtual_interface.html.markdown @@ -33,7 +33,7 @@ The following arguments are supported: * `name` - (Required) The name for the virtual interface. * `vlan` - (Required) The VLAN ID. * `amazon_address` - (Optional) The IPv4 CIDR address to use to send traffic to Amazon. Required for IPv4 BGP peers. -* `mtu` - (Optional) The maximum transmission unit (MTU) is the size, in bytes, of the largest permissible packet that can be passed over the connection. The MTU of a virtual private interface can be either 1500 or 9001 (jumbo frames). Default is 1500. +* `mtu` - (Optional) The maximum transmission unit (MTU) is the size, in bytes, of the largest permissible packet that can be passed over the connection. The MTU of a virtual private interface can be either 1500 or 9001 (jumbo frames). Default is 1500. `jumbo_frame_capable` will be exported as `true` if jumbo frames have been enabled. * `bgp_auth_key` - (Optional) The authentication key for BGP configuration. * `customer_address` - (Optional) The IPv4 CIDR destination address to which Amazon should send traffic. Required for IPv4 BGP peers. * `dx_gateway_id` - (Optional) The ID of the Direct Connect gateway to which to connect the virtual interface. From cdecb241b9de040225164299373d70987b886d40 Mon Sep 17 00:00:00 2001 From: "Aaron J. Smith" Date: Sat, 13 Oct 2018 08:01:29 -0500 Subject: [PATCH 04/14] adding acc test for mtu --- ...e_aws_dx_private_virtual_interface_test.go | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/aws/resource_aws_dx_private_virtual_interface_test.go b/aws/resource_aws_dx_private_virtual_interface_test.go index 85e29cc8614..548e7324c80 100644 --- a/aws/resource_aws_dx_private_virtual_interface_test.go +++ b/aws/resource_aws_dx_private_virtual_interface_test.go @@ -43,6 +43,15 @@ func TestAccAwsDxPrivateVirtualInterface_basic(t *testing.T) { resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "tags.Environment", "test"), ), }, + { + Config: testAccDxPrivateVirtualInterfaceConfig_mtuCapable(connectionId, vifName, bgpAsn), + Check: resource.ComposeTestCheckFunc( + testAccCheckAwsDxPrivateVirtualInterfaceExists("aws_dx_private_virtual_interface.foo"), + resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "name", vifName), + resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "mtu", "9001"), + resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "jumbo_frame_capable", "1"), + ), + }, // Test import. { ResourceName: "aws_dx_private_virtual_interface.foo", @@ -131,7 +140,6 @@ resource "aws_dx_private_virtual_interface" "foo" { vlan = 4094 address_family = "ipv4" bgp_asn = %d - mtu = 9001 } `, n, cid, n, bgpAsn) } @@ -152,7 +160,6 @@ resource "aws_dx_private_virtual_interface" "foo" { vlan = 4094 address_family = "ipv4" bgp_asn = %d - mtu = 9001 tags { Environment = "test" @@ -176,7 +183,27 @@ resource "aws_dx_private_virtual_interface" "foo" { vlan = 4094 address_family = "ipv4" bgp_asn = %d - mtu = 9001 } `, n, amzAsn, cid, n, bgpAsn) } + +func testAccDxPrivateVirtualInterfaceConfig_mtuCapable(cid, n string, bgpAsn int) string { + return fmt.Sprintf(` +resource "aws_vpn_gateway" "foo" { + tags { + Name = "%s" + } +} + +resource "aws_dx_private_virtual_interface" "foo" { + connection_id = "%s" + + vpn_gateway_id = "${aws_vpn_gateway.foo.id}" + name = "%s" + vlan = 4094 + address_family = "ipv4" + bgp_asn = %d + mtu = 9001 +} +`, n, cid, n, bgpAsn) +} From 4b3d2f0e3130506267f110802b520f91bf2b4e93 Mon Sep 17 00:00:00 2001 From: "Aaron J. Smith" Date: Sat, 13 Oct 2018 08:04:01 -0500 Subject: [PATCH 05/14] correcting exported value name --- aws/resource_aws_dx_private_virtual_interface.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_dx_private_virtual_interface.go b/aws/resource_aws_dx_private_virtual_interface.go index 6269af6fb50..47905e78bb2 100644 --- a/aws/resource_aws_dx_private_virtual_interface.go +++ b/aws/resource_aws_dx_private_virtual_interface.go @@ -90,7 +90,7 @@ func resourceAwsDxPrivateVirtualInterface() *schema.Resource { Computed: true, ForceNew: true, }, - "jumbo_frame_enabled": { + "jumbo_frame_capable": { Type: schema.TypeBool, Computed: true, }, From c4593ccbf5ca106d14bb28614546836f6a7a3240 Mon Sep 17 00:00:00 2001 From: "Aaron J. Smith" Date: Sat, 13 Oct 2018 08:41:03 -0500 Subject: [PATCH 06/14] setting default for mtu --- aws/resource_aws_dx_private_virtual_interface.go | 2 +- aws/resource_aws_dx_private_virtual_interface_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/aws/resource_aws_dx_private_virtual_interface.go b/aws/resource_aws_dx_private_virtual_interface.go index 47905e78bb2..dc4ac4bfd61 100644 --- a/aws/resource_aws_dx_private_virtual_interface.go +++ b/aws/resource_aws_dx_private_virtual_interface.go @@ -86,8 +86,8 @@ func resourceAwsDxPrivateVirtualInterface() *schema.Resource { }, "mtu": { Type: schema.TypeInt, + Default: 1500, Optional: true, - Computed: true, ForceNew: true, }, "jumbo_frame_capable": { diff --git a/aws/resource_aws_dx_private_virtual_interface_test.go b/aws/resource_aws_dx_private_virtual_interface_test.go index 548e7324c80..4a56bf352ed 100644 --- a/aws/resource_aws_dx_private_virtual_interface_test.go +++ b/aws/resource_aws_dx_private_virtual_interface_test.go @@ -203,7 +203,7 @@ resource "aws_dx_private_virtual_interface" "foo" { vlan = 4094 address_family = "ipv4" bgp_asn = %d - mtu = 9001 + mtu = 9001 } `, n, cid, n, bgpAsn) } From 636db337c04b1857b964896ea83102db87c3b088 Mon Sep 17 00:00:00 2001 From: "Aaron J. Smith" Date: Sun, 14 Oct 2018 22:06:25 -0500 Subject: [PATCH 07/14] validating mtu input & adding expanding vif update function --- aws/dx_vif.go | 18 +++++++++++++ ...source_aws_dx_private_virtual_interface.go | 27 ++++++++++++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/aws/dx_vif.go b/aws/dx_vif.go index ea659c7b6c9..b56dd6a0e67 100644 --- a/aws/dx_vif.go +++ b/aws/dx_vif.go @@ -26,6 +26,24 @@ func dxVirtualInterfaceRead(id string, conn *directconnect.DirectConnect) (*dire func dxVirtualInterfaceUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).dxconn + req := &directconnect.UpdateVirtualInterfaceAttributesInput{ + VirtualInterfaceId: aws.String(d.Id()), + } + + requestUpdate := false + if d.HasChange("mtu") { + req.Mtu = aws.Int64(int64(d.Get("mtu").(int))) + requestUpdate = true + } + + if requestUpdate { + log.Printf("[DEBUG] Modifying Virtual Interface attributes (%s), opts:\n%s", d.Id(), req) + _, err := conn.UpdateVirtualInterfaceAttributes(req) + if err != nil { + return fmt.Errorf("Error updating Virtual Interface attributes (%s), error: %s", d.Id(), err) + } + } + if err := setTagsDX(conn, d, d.Get("arn").(string)); err != nil { return err } diff --git a/aws/resource_aws_dx_private_virtual_interface.go b/aws/resource_aws_dx_private_virtual_interface.go index dc4ac4bfd61..3b99ff24cbd 100644 --- a/aws/resource_aws_dx_private_virtual_interface.go +++ b/aws/resource_aws_dx_private_virtual_interface.go @@ -85,10 +85,10 @@ func resourceAwsDxPrivateVirtualInterface() *schema.Resource { ForceNew: true, }, "mtu": { - Type: schema.TypeInt, - Default: 1500, - Optional: true, - ForceNew: true, + Type: schema.TypeInt, + Default: 1500, + Optional: true, + ValidateFunc: IntInSlice([]int{1500, 9001}), }, "jumbo_frame_capable": { Type: schema.TypeBool, @@ -235,3 +235,22 @@ func dxPrivateVirtualInterfaceWaitUntilAvailable(d *schema.ResourceData, conn *d directconnect.VirtualInterfaceStateDown, }) } + +func IntInSlice(valid []int) schema.SchemaValidateFunc { + return func(i interface{}, k string) (s []string, es []error) { + v, ok := i.(int) + if !ok { + es = append(es, fmt.Errorf("expected type of %s to be int", k)) + return + } + + for _, in := range valid { + if v == in { + return + } + } + + es = append(es, fmt.Errorf("expected %s to be one of %v, got %d", k, valid, v)) + return + } +} From 257a94ad24e6fb69edc4d7e5d0bcc66a95408d6c Mon Sep 17 00:00:00 2001 From: "Aaron J. Smith" Date: Mon, 15 Oct 2018 11:55:19 -0500 Subject: [PATCH 08/14] adding acc test for updating mtu --- ...e_aws_dx_private_virtual_interface_test.go | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/aws/resource_aws_dx_private_virtual_interface_test.go b/aws/resource_aws_dx_private_virtual_interface_test.go index 4a56bf352ed..93f64a4b6d2 100644 --- a/aws/resource_aws_dx_private_virtual_interface_test.go +++ b/aws/resource_aws_dx_private_virtual_interface_test.go @@ -88,6 +88,55 @@ func TestAccAwsDxPrivateVirtualInterface_dxGateway(t *testing.T) { }) } +func TestAccAwsDxPrivateVirtualInterface_mtuUpdate(t *testing.T) { + key := "DX_CONNECTION_ID" + connectionId := os.Getenv(key) + if connectionId == "" { + t.Skipf("Environment variable %s is not set", key) + } + vifName := fmt.Sprintf("terraform-testacc-dxvif-%s", acctest.RandString(5)) + bgpAsn := randIntRange(64512, 65534) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAwsDxPrivateVirtualInterfaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDxPrivateVirtualInterfaceConfig_noTags(connectionId, vifName, bgpAsn), + Check: resource.ComposeTestCheckFunc( + testAccCheckAwsDxPrivateVirtualInterfaceExists("aws_dx_private_virtual_interface.foo"), + resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "name", vifName), + ), + }, + { + Config: testAccDxPrivateVirtualInterfaceConfig_mtuCapable(connectionId, vifName, bgpAsn), + Check: resource.ComposeTestCheckFunc( + testAccCheckAwsDxPrivateVirtualInterfaceExists("aws_dx_private_virtual_interface.foo"), + resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "name", vifName), + resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "mtu", "9001"), + resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "jumbo_frame_capable", "1"), + ), + }, + { + Config: testAccDxPrivateVirtualInterfaceConfig_noTags(connectionId, vifName, bgpAsn), + Check: resource.ComposeTestCheckFunc( + testAccCheckAwsDxPrivateVirtualInterfaceExists("aws_dx_private_virtual_interface.foo"), + resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "name", vifName), + resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "mtu", "1500"), + resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "jumbo_frame_capable", "0"), + ), + }, + // Test import. + { + ResourceName: "aws_dx_private_virtual_interface.foo", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccCheckAwsDxPrivateVirtualInterfaceDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).dxconn From 4cff326fbc451a48d04871f28ffef8f761d4c884 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Sun, 21 Oct 2018 17:49:22 -0400 Subject: [PATCH 09/14] 'IntInSlice' -> 'validateIntegerInSlice'. --- ...source_aws_dx_private_virtual_interface.go | 21 +------- aws/validators.go | 19 +++++++ aws/validators_test.go | 51 +++++++++++++++++++ 3 files changed, 71 insertions(+), 20 deletions(-) diff --git a/aws/resource_aws_dx_private_virtual_interface.go b/aws/resource_aws_dx_private_virtual_interface.go index 3b99ff24cbd..d013acc8fc2 100644 --- a/aws/resource_aws_dx_private_virtual_interface.go +++ b/aws/resource_aws_dx_private_virtual_interface.go @@ -88,7 +88,7 @@ func resourceAwsDxPrivateVirtualInterface() *schema.Resource { Type: schema.TypeInt, Default: 1500, Optional: true, - ValidateFunc: IntInSlice([]int{1500, 9001}), + ValidateFunc: validateIntegerInSlice([]int{1500, 9001}), }, "jumbo_frame_capable": { Type: schema.TypeBool, @@ -235,22 +235,3 @@ func dxPrivateVirtualInterfaceWaitUntilAvailable(d *schema.ResourceData, conn *d directconnect.VirtualInterfaceStateDown, }) } - -func IntInSlice(valid []int) schema.SchemaValidateFunc { - return func(i interface{}, k string) (s []string, es []error) { - v, ok := i.(int) - if !ok { - es = append(es, fmt.Errorf("expected type of %s to be int", k)) - return - } - - for _, in := range valid { - if v == in { - return - } - } - - es = append(es, fmt.Errorf("expected %s to be one of %v, got %d", k, valid, v)) - return - } -} diff --git a/aws/validators.go b/aws/validators.go index 3d064ea0de5..f16a0f887c3 100644 --- a/aws/validators.go +++ b/aws/validators.go @@ -365,6 +365,25 @@ func validateIntegerInRange(min, max int) schema.SchemaValidateFunc { } } +func validateIntegerInSlice(valid []int) schema.SchemaValidateFunc { + return func(i interface{}, k string) (s []string, es []error) { + v, ok := i.(int) + if !ok { + es = append(es, fmt.Errorf("expected type of %s to be int", k)) + return + } + + for _, in := range valid { + if v == in { + return + } + } + + es = append(es, fmt.Errorf("expected %s to be one of %v, got %d", k, valid, v)) + return + } +} + func validateCloudWatchEventTargetId(v interface{}, k string) (ws []string, errors []error) { value := v.(string) if len(value) > 64 { diff --git a/aws/validators_test.go b/aws/validators_test.go index 8ea201bfdd4..bb5349b5873 100644 --- a/aws/validators_test.go +++ b/aws/validators_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/aws/aws-sdk-go/service/cognitoidentity" + "github.com/hashicorp/terraform/helper/schema" ) func TestValidateRFC3339TimeString(t *testing.T) { @@ -648,6 +649,56 @@ func TestValidateIntegerInRange(t *testing.T) { } } +func TestValidateIntegerInSlice(t *testing.T) { + cases := []struct { + val interface{} + f schema.SchemaValidateFunc + expectedErr *regexp.Regexp + }{ + { + val: 42, + f: validateIntegerInSlice([]int{2, 4, 42, 420}), + }, + { + val: 42, + f: validateIntegerInSlice([]int{0, 43}), + expectedErr: regexp.MustCompile("expected [\\w]+ to be one of \\[0 43\\], got 42"), + }, + { + val: "42", + f: validateIntegerInSlice([]int{0, 42}), + expectedErr: regexp.MustCompile("expected type of [\\w]+ to be int"), + }, + } + + matchErr := func(errs []error, r *regexp.Regexp) bool { + // err must match one provided + for _, err := range errs { + if r.MatchString(err.Error()) { + return true + } + } + + return false + } + + for i, tc := range cases { + _, errs := tc.f(tc.val, "test_property") + + if len(errs) == 0 && tc.expectedErr == nil { + continue + } + + if len(errs) != 0 && tc.expectedErr == nil { + t.Fatalf("expected test case %d to produce no errors, got %v", i, errs) + } + + if !matchErr(errs, tc.expectedErr) { + t.Fatalf("expected test case %d to produce error matching \"%s\", got %v", i, tc.expectedErr, errs) + } + } +} + func TestResourceAWSElastiCacheClusterIdValidation(t *testing.T) { cases := []struct { Value string From 0cf60abce654fb32cba7666b6c2e4d687e97ea15 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Sun, 21 Oct 2018 18:27:51 -0400 Subject: [PATCH 10/14] Add Update timeout to r/aws_dx_private_virtual_interface. --- aws/dx_vif.go | 12 ++++----- ...aws_dx_hosted_private_virtual_interface.go | 7 +++--- ...sted_private_virtual_interface_accepter.go | 7 +++--- ..._aws_dx_hosted_public_virtual_interface.go | 7 +++--- ...osted_public_virtual_interface_accepter.go | 7 +++--- ...source_aws_dx_private_virtual_interface.go | 15 ++++++----- ...e_aws_dx_private_virtual_interface_test.go | 25 ++++--------------- ...esource_aws_dx_public_virtual_interface.go | 7 +++--- ...dx_private_virtual_interface.html.markdown | 5 +++- 9 files changed, 44 insertions(+), 48 deletions(-) diff --git a/aws/dx_vif.go b/aws/dx_vif.go index b56dd6a0e67..ebf0a54e045 100644 --- a/aws/dx_vif.go +++ b/aws/dx_vif.go @@ -37,10 +37,10 @@ func dxVirtualInterfaceUpdate(d *schema.ResourceData, meta interface{}) error { } if requestUpdate { - log.Printf("[DEBUG] Modifying Virtual Interface attributes (%s), opts:\n%s", d.Id(), req) + log.Printf("[DEBUG] Modifying Direct Connect virtual interface attributes: %#v", req) _, err := conn.UpdateVirtualInterfaceAttributes(req) if err != nil { - return fmt.Errorf("Error updating Virtual Interface attributes (%s), error: %s", d.Id(), err) + return fmt.Errorf("Error modifying Direct Connect virtual interface (%s) attributes, error: %s", d.Id(), err) } } @@ -115,17 +115,17 @@ func dxVirtualInterfaceStateRefresh(conn *directconnect.DirectConnect, vifId str } } -func dxVirtualInterfaceWaitUntilAvailable(d *schema.ResourceData, conn *directconnect.DirectConnect, pending, target []string) error { +func dxVirtualInterfaceWaitUntilAvailable(conn *directconnect.DirectConnect, vifId string, timeout time.Duration, pending, target []string) error { stateConf := &resource.StateChangeConf{ Pending: pending, Target: target, - Refresh: dxVirtualInterfaceStateRefresh(conn, d.Id()), - Timeout: d.Timeout(schema.TimeoutCreate), + Refresh: dxVirtualInterfaceStateRefresh(conn, vifId), + Timeout: timeout, Delay: 10 * time.Second, MinTimeout: 5 * time.Second, } if _, err := stateConf.WaitForState(); err != nil { - return fmt.Errorf("Error waiting for Direct Connect virtual interface (%s) to become available: %s", d.Id(), err) + return fmt.Errorf("Error waiting for Direct Connect virtual interface (%s) to become available: %s", vifId, err) } return nil diff --git a/aws/resource_aws_dx_hosted_private_virtual_interface.go b/aws/resource_aws_dx_hosted_private_virtual_interface.go index f0ce581ff78..c03bcccf808 100644 --- a/aws/resource_aws_dx_hosted_private_virtual_interface.go +++ b/aws/resource_aws_dx_hosted_private_virtual_interface.go @@ -125,7 +125,7 @@ func resourceAwsDxHostedPrivateVirtualInterfaceCreate(d *schema.ResourceData, me }.String() d.Set("arn", arn) - if err := dxHostedPrivateVirtualInterfaceWaitUntilAvailable(d, conn); err != nil { + if err := dxHostedPrivateVirtualInterfaceWaitUntilAvailable(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return err } @@ -175,10 +175,11 @@ func resourceAwsDxHostedPrivateVirtualInterfaceImport(d *schema.ResourceData, me return []*schema.ResourceData{d}, nil } -func dxHostedPrivateVirtualInterfaceWaitUntilAvailable(d *schema.ResourceData, conn *directconnect.DirectConnect) error { +func dxHostedPrivateVirtualInterfaceWaitUntilAvailable(conn *directconnect.DirectConnect, vifId string, timeout time.Duration) error { return dxVirtualInterfaceWaitUntilAvailable( - d, conn, + vifId, + timeout, []string{ directconnect.VirtualInterfaceStatePending, }, diff --git a/aws/resource_aws_dx_hosted_private_virtual_interface_accepter.go b/aws/resource_aws_dx_hosted_private_virtual_interface_accepter.go index 855061c9eef..87ed7673b19 100644 --- a/aws/resource_aws_dx_hosted_private_virtual_interface_accepter.go +++ b/aws/resource_aws_dx_hosted_private_virtual_interface_accepter.go @@ -90,7 +90,7 @@ func resourceAwsDxHostedPrivateVirtualInterfaceAccepterCreate(d *schema.Resource }.String() d.Set("arn", arn) - if err := dxHostedPrivateVirtualInterfaceAccepterWaitUntilAvailable(d, conn); err != nil { + if err := dxHostedPrivateVirtualInterfaceAccepterWaitUntilAvailable(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return err } @@ -153,10 +153,11 @@ func resourceAwsDxHostedPrivateVirtualInterfaceAccepterImport(d *schema.Resource return []*schema.ResourceData{d}, nil } -func dxHostedPrivateVirtualInterfaceAccepterWaitUntilAvailable(d *schema.ResourceData, conn *directconnect.DirectConnect) error { +func dxHostedPrivateVirtualInterfaceAccepterWaitUntilAvailable(conn *directconnect.DirectConnect, vifId string, timeout time.Duration) error { return dxVirtualInterfaceWaitUntilAvailable( - d, conn, + vifId, + timeout, []string{ directconnect.VirtualInterfaceStateConfirming, directconnect.VirtualInterfaceStatePending, diff --git a/aws/resource_aws_dx_hosted_public_virtual_interface.go b/aws/resource_aws_dx_hosted_public_virtual_interface.go index a8cede3c7bb..850acd898f4 100644 --- a/aws/resource_aws_dx_hosted_public_virtual_interface.go +++ b/aws/resource_aws_dx_hosted_public_virtual_interface.go @@ -147,7 +147,7 @@ func resourceAwsDxHostedPublicVirtualInterfaceCreate(d *schema.ResourceData, met }.String() d.Set("arn", arn) - if err := dxHostedPublicVirtualInterfaceWaitUntilAvailable(d, conn); err != nil { + if err := dxHostedPublicVirtualInterfaceWaitUntilAvailable(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return err } @@ -198,10 +198,11 @@ func resourceAwsDxHostedPublicVirtualInterfaceImport(d *schema.ResourceData, met return []*schema.ResourceData{d}, nil } -func dxHostedPublicVirtualInterfaceWaitUntilAvailable(d *schema.ResourceData, conn *directconnect.DirectConnect) error { +func dxHostedPublicVirtualInterfaceWaitUntilAvailable(conn *directconnect.DirectConnect, vifId string, timeout time.Duration) error { return dxVirtualInterfaceWaitUntilAvailable( - d, conn, + vifId, + timeout, []string{ directconnect.VirtualInterfaceStatePending, }, diff --git a/aws/resource_aws_dx_hosted_public_virtual_interface_accepter.go b/aws/resource_aws_dx_hosted_public_virtual_interface_accepter.go index 46bafff5917..b3cfc696358 100644 --- a/aws/resource_aws_dx_hosted_public_virtual_interface_accepter.go +++ b/aws/resource_aws_dx_hosted_public_virtual_interface_accepter.go @@ -65,7 +65,7 @@ func resourceAwsDxHostedPublicVirtualInterfaceAccepterCreate(d *schema.ResourceD }.String() d.Set("arn", arn) - if err := dxHostedPublicVirtualInterfaceAccepterWaitUntilAvailable(d, conn); err != nil { + if err := dxHostedPublicVirtualInterfaceAccepterWaitUntilAvailable(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return err } @@ -127,10 +127,11 @@ func resourceAwsDxHostedPublicVirtualInterfaceAccepterImport(d *schema.ResourceD return []*schema.ResourceData{d}, nil } -func dxHostedPublicVirtualInterfaceAccepterWaitUntilAvailable(d *schema.ResourceData, conn *directconnect.DirectConnect) error { +func dxHostedPublicVirtualInterfaceAccepterWaitUntilAvailable(conn *directconnect.DirectConnect, vifId string, timeout time.Duration) error { return dxVirtualInterfaceWaitUntilAvailable( - d, conn, + vifId, + timeout, []string{ directconnect.VirtualInterfaceStateConfirming, directconnect.VirtualInterfaceStatePending, diff --git a/aws/resource_aws_dx_private_virtual_interface.go b/aws/resource_aws_dx_private_virtual_interface.go index d013acc8fc2..f5851bd9da4 100644 --- a/aws/resource_aws_dx_private_virtual_interface.go +++ b/aws/resource_aws_dx_private_virtual_interface.go @@ -99,6 +99,7 @@ func resourceAwsDxPrivateVirtualInterface() *schema.Resource { Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(10 * time.Minute), + Update: schema.DefaultTimeout(10 * time.Minute), Delete: schema.DefaultTimeout(10 * time.Minute), }, } @@ -139,9 +140,6 @@ func resourceAwsDxPrivateVirtualInterfaceCreate(d *schema.ResourceData, meta int if v, ok := d.GetOk("amazon_address"); ok && v.(string) != "" { req.NewPrivateVirtualInterface.AmazonAddress = aws.String(v.(string)) } - if v, ok := d.GetOk("mtu"); ok && v.(int) != 0 { - req.NewPrivateVirtualInterface.Mtu = aws.Int64(int64(v.(int))) - } log.Printf("[DEBUG] Creating Direct Connect private virtual interface: %#v", req) resp, err := conn.CreatePrivateVirtualInterface(req) @@ -159,7 +157,7 @@ func resourceAwsDxPrivateVirtualInterfaceCreate(d *schema.ResourceData, meta int }.String() d.Set("arn", arn) - if err := dxPrivateVirtualInterfaceWaitUntilAvailable(d, conn); err != nil { + if err := dxPrivateVirtualInterfaceWaitUntilAvailable(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return err } @@ -203,6 +201,10 @@ func resourceAwsDxPrivateVirtualInterfaceUpdate(d *schema.ResourceData, meta int return err } + if err := dxPrivateVirtualInterfaceWaitUntilAvailable(meta.(*AWSClient).dxconn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { + return err + } + return resourceAwsDxPrivateVirtualInterfaceRead(d, meta) } @@ -223,10 +225,11 @@ func resourceAwsDxPrivateVirtualInterfaceImport(d *schema.ResourceData, meta int return []*schema.ResourceData{d}, nil } -func dxPrivateVirtualInterfaceWaitUntilAvailable(d *schema.ResourceData, conn *directconnect.DirectConnect) error { +func dxPrivateVirtualInterfaceWaitUntilAvailable(conn *directconnect.DirectConnect, vifId string, timeout time.Duration) error { return dxVirtualInterfaceWaitUntilAvailable( - d, conn, + vifId, + timeout, []string{ directconnect.VirtualInterfaceStatePending, }, diff --git a/aws/resource_aws_dx_private_virtual_interface_test.go b/aws/resource_aws_dx_private_virtual_interface_test.go index 93f64a4b6d2..a8c1496c0a4 100644 --- a/aws/resource_aws_dx_private_virtual_interface_test.go +++ b/aws/resource_aws_dx_private_virtual_interface_test.go @@ -43,15 +43,6 @@ func TestAccAwsDxPrivateVirtualInterface_basic(t *testing.T) { resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "tags.Environment", "test"), ), }, - { - Config: testAccDxPrivateVirtualInterfaceConfig_mtuCapable(connectionId, vifName, bgpAsn), - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsDxPrivateVirtualInterfaceExists("aws_dx_private_virtual_interface.foo"), - resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "name", vifName), - resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "mtu", "9001"), - resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "jumbo_frame_capable", "1"), - ), - }, // Test import. { ResourceName: "aws_dx_private_virtual_interface.foo", @@ -107,15 +98,16 @@ func TestAccAwsDxPrivateVirtualInterface_mtuUpdate(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAwsDxPrivateVirtualInterfaceExists("aws_dx_private_virtual_interface.foo"), resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "name", vifName), + resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "mtu", "1500"), + resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "jumbo_frame_capable", "1"), ), }, { - Config: testAccDxPrivateVirtualInterfaceConfig_mtuCapable(connectionId, vifName, bgpAsn), + Config: testAccDxPrivateVirtualInterfaceConfig_jumboFrames(connectionId, vifName, bgpAsn), Check: resource.ComposeTestCheckFunc( testAccCheckAwsDxPrivateVirtualInterfaceExists("aws_dx_private_virtual_interface.foo"), resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "name", vifName), resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "mtu", "9001"), - resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "jumbo_frame_capable", "1"), ), }, { @@ -124,15 +116,8 @@ func TestAccAwsDxPrivateVirtualInterface_mtuUpdate(t *testing.T) { testAccCheckAwsDxPrivateVirtualInterfaceExists("aws_dx_private_virtual_interface.foo"), resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "name", vifName), resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "mtu", "1500"), - resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "jumbo_frame_capable", "0"), ), }, - // Test import. - { - ResourceName: "aws_dx_private_virtual_interface.foo", - ImportState: true, - ImportStateVerify: true, - }, }, }) } @@ -236,7 +221,7 @@ resource "aws_dx_private_virtual_interface" "foo" { `, n, amzAsn, cid, n, bgpAsn) } -func testAccDxPrivateVirtualInterfaceConfig_mtuCapable(cid, n string, bgpAsn int) string { +func testAccDxPrivateVirtualInterfaceConfig_jumboFrames(cid, n string, bgpAsn int) string { return fmt.Sprintf(` resource "aws_vpn_gateway" "foo" { tags { @@ -252,7 +237,7 @@ resource "aws_dx_private_virtual_interface" "foo" { vlan = 4094 address_family = "ipv4" bgp_asn = %d - mtu = 9001 + mtu = 9001 } `, n, cid, n, bgpAsn) } diff --git a/aws/resource_aws_dx_public_virtual_interface.go b/aws/resource_aws_dx_public_virtual_interface.go index bc072fe6d0d..26d3cb3a1a3 100644 --- a/aws/resource_aws_dx_public_virtual_interface.go +++ b/aws/resource_aws_dx_public_virtual_interface.go @@ -131,7 +131,7 @@ func resourceAwsDxPublicVirtualInterfaceCreate(d *schema.ResourceData, meta inte }.String() d.Set("arn", arn) - if err := dxPublicVirtualInterfaceWaitUntilAvailable(d, conn); err != nil { + if err := dxPublicVirtualInterfaceWaitUntilAvailable(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return err } @@ -208,10 +208,11 @@ func resourceAwsDxPublicVirtualInterfaceCustomizeDiff(diff *schema.ResourceDiff, return nil } -func dxPublicVirtualInterfaceWaitUntilAvailable(d *schema.ResourceData, conn *directconnect.DirectConnect) error { +func dxPublicVirtualInterfaceWaitUntilAvailable(conn *directconnect.DirectConnect, vifId string, timeout time.Duration) error { return dxVirtualInterfaceWaitUntilAvailable( - d, conn, + vifId, + timeout, []string{ directconnect.VirtualInterfaceStatePending, }, diff --git a/website/docs/r/dx_private_virtual_interface.html.markdown b/website/docs/r/dx_private_virtual_interface.html.markdown index 68a84721244..10ffd4219f2 100644 --- a/website/docs/r/dx_private_virtual_interface.html.markdown +++ b/website/docs/r/dx_private_virtual_interface.html.markdown @@ -33,7 +33,8 @@ The following arguments are supported: * `name` - (Required) The name for the virtual interface. * `vlan` - (Required) The VLAN ID. * `amazon_address` - (Optional) The IPv4 CIDR address to use to send traffic to Amazon. Required for IPv4 BGP peers. -* `mtu` - (Optional) The maximum transmission unit (MTU) is the size, in bytes, of the largest permissible packet that can be passed over the connection. The MTU of a virtual private interface can be either 1500 or 9001 (jumbo frames). Default is 1500. `jumbo_frame_capable` will be exported as `true` if jumbo frames have been enabled. +* `mtu` - (Optional) The maximum transmission unit (MTU) is the size, in bytes, of the largest permissible packet that can be passed over the connection. +The MTU of a virtual private interface can be either `1500` or `9001` (jumbo frames). Default is `1500`. * `bgp_auth_key` - (Optional) The authentication key for BGP configuration. * `customer_address` - (Optional) The IPv4 CIDR destination address to which Amazon should send traffic. Required for IPv4 BGP peers. * `dx_gateway_id` - (Optional) The ID of the Direct Connect gateway to which to connect the virtual interface. @@ -46,6 +47,7 @@ In addition to all arguments above, the following attributes are exported: * `id` - The ID of the virtual interface. * `arn` - The ARN of the virtual interface. +* `jumbo_frame_capable` - Indicates whether jumbo frames (9001 MTU) are supported. ## Timeouts @@ -53,6 +55,7 @@ In addition to all arguments above, the following attributes are exported: [Timeouts](/docs/configuration/resources.html#timeouts) configuration options: - `create` - (Default `10 minutes`) Used for creating virtual interface +- `update` - (Default `10 minutes`) Used for virtual interface modifications - `delete` - (Default `10 minutes`) Used for destroying virtual interface ## Import From bd5798b3f942f7f36da671cb3917ba2d6b86fcbf Mon Sep 17 00:00:00 2001 From: "Aaron J. Smith" Date: Mon, 22 Oct 2018 10:24:33 -0500 Subject: [PATCH 11/14] pulling in ewbankkit changes --- ...source_aws_dx_private_virtual_interface.go | 36 ++++++------------- ...e_aws_dx_private_virtual_interface_test.go | 29 ++++----------- ...dx_private_virtual_interface.html.markdown | 5 ++- 3 files changed, 21 insertions(+), 49 deletions(-) diff --git a/aws/resource_aws_dx_private_virtual_interface.go b/aws/resource_aws_dx_private_virtual_interface.go index 3b99ff24cbd..f5851bd9da4 100644 --- a/aws/resource_aws_dx_private_virtual_interface.go +++ b/aws/resource_aws_dx_private_virtual_interface.go @@ -88,7 +88,7 @@ func resourceAwsDxPrivateVirtualInterface() *schema.Resource { Type: schema.TypeInt, Default: 1500, Optional: true, - ValidateFunc: IntInSlice([]int{1500, 9001}), + ValidateFunc: validateIntegerInSlice([]int{1500, 9001}), }, "jumbo_frame_capable": { Type: schema.TypeBool, @@ -99,6 +99,7 @@ func resourceAwsDxPrivateVirtualInterface() *schema.Resource { Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(10 * time.Minute), + Update: schema.DefaultTimeout(10 * time.Minute), Delete: schema.DefaultTimeout(10 * time.Minute), }, } @@ -139,9 +140,6 @@ func resourceAwsDxPrivateVirtualInterfaceCreate(d *schema.ResourceData, meta int if v, ok := d.GetOk("amazon_address"); ok && v.(string) != "" { req.NewPrivateVirtualInterface.AmazonAddress = aws.String(v.(string)) } - if v, ok := d.GetOk("mtu"); ok && v.(int) != 0 { - req.NewPrivateVirtualInterface.Mtu = aws.Int64(int64(v.(int))) - } log.Printf("[DEBUG] Creating Direct Connect private virtual interface: %#v", req) resp, err := conn.CreatePrivateVirtualInterface(req) @@ -159,7 +157,7 @@ func resourceAwsDxPrivateVirtualInterfaceCreate(d *schema.ResourceData, meta int }.String() d.Set("arn", arn) - if err := dxPrivateVirtualInterfaceWaitUntilAvailable(d, conn); err != nil { + if err := dxPrivateVirtualInterfaceWaitUntilAvailable(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return err } @@ -203,6 +201,10 @@ func resourceAwsDxPrivateVirtualInterfaceUpdate(d *schema.ResourceData, meta int return err } + if err := dxPrivateVirtualInterfaceWaitUntilAvailable(meta.(*AWSClient).dxconn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { + return err + } + return resourceAwsDxPrivateVirtualInterfaceRead(d, meta) } @@ -223,10 +225,11 @@ func resourceAwsDxPrivateVirtualInterfaceImport(d *schema.ResourceData, meta int return []*schema.ResourceData{d}, nil } -func dxPrivateVirtualInterfaceWaitUntilAvailable(d *schema.ResourceData, conn *directconnect.DirectConnect) error { +func dxPrivateVirtualInterfaceWaitUntilAvailable(conn *directconnect.DirectConnect, vifId string, timeout time.Duration) error { return dxVirtualInterfaceWaitUntilAvailable( - d, conn, + vifId, + timeout, []string{ directconnect.VirtualInterfaceStatePending, }, @@ -235,22 +238,3 @@ func dxPrivateVirtualInterfaceWaitUntilAvailable(d *schema.ResourceData, conn *d directconnect.VirtualInterfaceStateDown, }) } - -func IntInSlice(valid []int) schema.SchemaValidateFunc { - return func(i interface{}, k string) (s []string, es []error) { - v, ok := i.(int) - if !ok { - es = append(es, fmt.Errorf("expected type of %s to be int", k)) - return - } - - for _, in := range valid { - if v == in { - return - } - } - - es = append(es, fmt.Errorf("expected %s to be one of %v, got %d", k, valid, v)) - return - } -} diff --git a/aws/resource_aws_dx_private_virtual_interface_test.go b/aws/resource_aws_dx_private_virtual_interface_test.go index 93f64a4b6d2..850a2fc8222 100644 --- a/aws/resource_aws_dx_private_virtual_interface_test.go +++ b/aws/resource_aws_dx_private_virtual_interface_test.go @@ -21,7 +21,7 @@ func TestAccAwsDxPrivateVirtualInterface_basic(t *testing.T) { vifName := fmt.Sprintf("terraform-testacc-dxvif-%s", acctest.RandString(5)) bgpAsn := randIntRange(64512, 65534) - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAwsDxPrivateVirtualInterfaceDestroy, @@ -43,15 +43,6 @@ func TestAccAwsDxPrivateVirtualInterface_basic(t *testing.T) { resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "tags.Environment", "test"), ), }, - { - Config: testAccDxPrivateVirtualInterfaceConfig_mtuCapable(connectionId, vifName, bgpAsn), - Check: resource.ComposeTestCheckFunc( - testAccCheckAwsDxPrivateVirtualInterfaceExists("aws_dx_private_virtual_interface.foo"), - resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "name", vifName), - resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "mtu", "9001"), - resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "jumbo_frame_capable", "1"), - ), - }, // Test import. { ResourceName: "aws_dx_private_virtual_interface.foo", @@ -72,7 +63,7 @@ func TestAccAwsDxPrivateVirtualInterface_dxGateway(t *testing.T) { amzAsn := randIntRange(64512, 65534) bgpAsn := randIntRange(64512, 65534) - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAwsDxPrivateVirtualInterfaceDestroy, @@ -107,15 +98,16 @@ func TestAccAwsDxPrivateVirtualInterface_mtuUpdate(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAwsDxPrivateVirtualInterfaceExists("aws_dx_private_virtual_interface.foo"), resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "name", vifName), + resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "mtu", "1500"), + resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "jumbo_frame_capable", "1"), ), }, { - Config: testAccDxPrivateVirtualInterfaceConfig_mtuCapable(connectionId, vifName, bgpAsn), + Config: testAccDxPrivateVirtualInterfaceConfig_jumboFrames(connectionId, vifName, bgpAsn), Check: resource.ComposeTestCheckFunc( testAccCheckAwsDxPrivateVirtualInterfaceExists("aws_dx_private_virtual_interface.foo"), resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "name", vifName), resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "mtu", "9001"), - resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "jumbo_frame_capable", "1"), ), }, { @@ -124,15 +116,8 @@ func TestAccAwsDxPrivateVirtualInterface_mtuUpdate(t *testing.T) { testAccCheckAwsDxPrivateVirtualInterfaceExists("aws_dx_private_virtual_interface.foo"), resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "name", vifName), resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "mtu", "1500"), - resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "jumbo_frame_capable", "0"), ), }, - // Test import. - { - ResourceName: "aws_dx_private_virtual_interface.foo", - ImportState: true, - ImportStateVerify: true, - }, }, }) } @@ -236,7 +221,7 @@ resource "aws_dx_private_virtual_interface" "foo" { `, n, amzAsn, cid, n, bgpAsn) } -func testAccDxPrivateVirtualInterfaceConfig_mtuCapable(cid, n string, bgpAsn int) string { +func testAccDxPrivateVirtualInterfaceConfig_jumboFrames(cid, n string, bgpAsn int) string { return fmt.Sprintf(` resource "aws_vpn_gateway" "foo" { tags { @@ -252,7 +237,7 @@ resource "aws_dx_private_virtual_interface" "foo" { vlan = 4094 address_family = "ipv4" bgp_asn = %d - mtu = 9001 + mtu = 9001 } `, n, cid, n, bgpAsn) } diff --git a/website/docs/r/dx_private_virtual_interface.html.markdown b/website/docs/r/dx_private_virtual_interface.html.markdown index 68a84721244..10ffd4219f2 100644 --- a/website/docs/r/dx_private_virtual_interface.html.markdown +++ b/website/docs/r/dx_private_virtual_interface.html.markdown @@ -33,7 +33,8 @@ The following arguments are supported: * `name` - (Required) The name for the virtual interface. * `vlan` - (Required) The VLAN ID. * `amazon_address` - (Optional) The IPv4 CIDR address to use to send traffic to Amazon. Required for IPv4 BGP peers. -* `mtu` - (Optional) The maximum transmission unit (MTU) is the size, in bytes, of the largest permissible packet that can be passed over the connection. The MTU of a virtual private interface can be either 1500 or 9001 (jumbo frames). Default is 1500. `jumbo_frame_capable` will be exported as `true` if jumbo frames have been enabled. +* `mtu` - (Optional) The maximum transmission unit (MTU) is the size, in bytes, of the largest permissible packet that can be passed over the connection. +The MTU of a virtual private interface can be either `1500` or `9001` (jumbo frames). Default is `1500`. * `bgp_auth_key` - (Optional) The authentication key for BGP configuration. * `customer_address` - (Optional) The IPv4 CIDR destination address to which Amazon should send traffic. Required for IPv4 BGP peers. * `dx_gateway_id` - (Optional) The ID of the Direct Connect gateway to which to connect the virtual interface. @@ -46,6 +47,7 @@ In addition to all arguments above, the following attributes are exported: * `id` - The ID of the virtual interface. * `arn` - The ARN of the virtual interface. +* `jumbo_frame_capable` - Indicates whether jumbo frames (9001 MTU) are supported. ## Timeouts @@ -53,6 +55,7 @@ In addition to all arguments above, the following attributes are exported: [Timeouts](/docs/configuration/resources.html#timeouts) configuration options: - `create` - (Default `10 minutes`) Used for creating virtual interface +- `update` - (Default `10 minutes`) Used for virtual interface modifications - `delete` - (Default `10 minutes`) Used for destroying virtual interface ## Import From 1d7542874cecd0fddbe023e86334d53f2dbcd337 Mon Sep 17 00:00:00 2001 From: "Aaron J. Smith" Date: Mon, 22 Oct 2018 12:38:53 -0500 Subject: [PATCH 12/14] forgot a missing file from previous commit --- aws/dx_vif.go | 12 ++++++------ aws/resource_aws_dx_private_virtual_interface.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/aws/dx_vif.go b/aws/dx_vif.go index b56dd6a0e67..ebf0a54e045 100644 --- a/aws/dx_vif.go +++ b/aws/dx_vif.go @@ -37,10 +37,10 @@ func dxVirtualInterfaceUpdate(d *schema.ResourceData, meta interface{}) error { } if requestUpdate { - log.Printf("[DEBUG] Modifying Virtual Interface attributes (%s), opts:\n%s", d.Id(), req) + log.Printf("[DEBUG] Modifying Direct Connect virtual interface attributes: %#v", req) _, err := conn.UpdateVirtualInterfaceAttributes(req) if err != nil { - return fmt.Errorf("Error updating Virtual Interface attributes (%s), error: %s", d.Id(), err) + return fmt.Errorf("Error modifying Direct Connect virtual interface (%s) attributes, error: %s", d.Id(), err) } } @@ -115,17 +115,17 @@ func dxVirtualInterfaceStateRefresh(conn *directconnect.DirectConnect, vifId str } } -func dxVirtualInterfaceWaitUntilAvailable(d *schema.ResourceData, conn *directconnect.DirectConnect, pending, target []string) error { +func dxVirtualInterfaceWaitUntilAvailable(conn *directconnect.DirectConnect, vifId string, timeout time.Duration, pending, target []string) error { stateConf := &resource.StateChangeConf{ Pending: pending, Target: target, - Refresh: dxVirtualInterfaceStateRefresh(conn, d.Id()), - Timeout: d.Timeout(schema.TimeoutCreate), + Refresh: dxVirtualInterfaceStateRefresh(conn, vifId), + Timeout: timeout, Delay: 10 * time.Second, MinTimeout: 5 * time.Second, } if _, err := stateConf.WaitForState(); err != nil { - return fmt.Errorf("Error waiting for Direct Connect virtual interface (%s) to become available: %s", d.Id(), err) + return fmt.Errorf("Error waiting for Direct Connect virtual interface (%s) to become available: %s", vifId, err) } return nil diff --git a/aws/resource_aws_dx_private_virtual_interface.go b/aws/resource_aws_dx_private_virtual_interface.go index f5851bd9da4..50417cbd079 100644 --- a/aws/resource_aws_dx_private_virtual_interface.go +++ b/aws/resource_aws_dx_private_virtual_interface.go @@ -88,7 +88,7 @@ func resourceAwsDxPrivateVirtualInterface() *schema.Resource { Type: schema.TypeInt, Default: 1500, Optional: true, - ValidateFunc: validateIntegerInSlice([]int{1500, 9001}), + ValidateFunc: validateIntInSlice([]int{1500, 9001}), }, "jumbo_frame_capable": { Type: schema.TypeBool, From 77e465a12cc1000f6bac27dcb4f271d9099885c1 Mon Sep 17 00:00:00 2001 From: "Aaron J. Smith" Date: Mon, 22 Oct 2018 17:09:22 -0500 Subject: [PATCH 13/14] removing conflict cruft --- aws/resource_aws_dx_private_virtual_interface.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/aws/resource_aws_dx_private_virtual_interface.go b/aws/resource_aws_dx_private_virtual_interface.go index 11b42e26c4a..f5851bd9da4 100644 --- a/aws/resource_aws_dx_private_virtual_interface.go +++ b/aws/resource_aws_dx_private_virtual_interface.go @@ -88,11 +88,7 @@ func resourceAwsDxPrivateVirtualInterface() *schema.Resource { Type: schema.TypeInt, Default: 1500, Optional: true, -<<<<<<< HEAD - ValidateFunc: validateIntInSlice([]int{1500, 9001}), -======= ValidateFunc: validateIntegerInSlice([]int{1500, 9001}), ->>>>>>> exbankkit/slapula-dx-private-virtual-interface-mtu }, "jumbo_frame_capable": { Type: schema.TypeBool, From da69517c8d918611b8ab9599b7e82ee1445c8be4 Mon Sep 17 00:00:00 2001 From: "Aaron J. Smith" Date: Tue, 23 Oct 2018 08:35:11 -0500 Subject: [PATCH 14/14] changing 1 to true --- aws/resource_aws_dx_private_virtual_interface_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_dx_private_virtual_interface_test.go b/aws/resource_aws_dx_private_virtual_interface_test.go index 850a2fc8222..17214c4acc7 100644 --- a/aws/resource_aws_dx_private_virtual_interface_test.go +++ b/aws/resource_aws_dx_private_virtual_interface_test.go @@ -99,7 +99,7 @@ func TestAccAwsDxPrivateVirtualInterface_mtuUpdate(t *testing.T) { testAccCheckAwsDxPrivateVirtualInterfaceExists("aws_dx_private_virtual_interface.foo"), resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "name", vifName), resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "mtu", "1500"), - resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "jumbo_frame_capable", "1"), + resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "jumbo_frame_capable", "true"), ), }, {