Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_dx_private_virtual_interface: Update resource to support MTU param #6141

Merged
merged 18 commits into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions aws/dx_vif.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 Direct Connect virtual interface attributes: %#v", req)
_, err := conn.UpdateVirtualInterfaceAttributes(req)
if err != nil {
return fmt.Errorf("Error modifying Direct Connect virtual interface (%s) attributes, error: %s", d.Id(), err)
}
}

if err := setTagsDX(conn, d, d.Get("arn").(string)); err != nil {
return err
}
Expand Down Expand Up @@ -97,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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

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
Expand Down
7 changes: 4 additions & 3 deletions aws/resource_aws_dx_hosted_private_virtual_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions aws/resource_aws_dx_hosted_public_virtual_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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,
Expand Down
25 changes: 22 additions & 3 deletions aws/resource_aws_dx_private_virtual_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,22 @@ func resourceAwsDxPrivateVirtualInterface() *schema.Resource {
Computed: true,
ForceNew: true,
},
"mtu": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type: schema.TypeInt,
Default: 1500,
Optional: true,
ValidateFunc: validateIntegerInSlice([]int{1500, 9001}),
},
"jumbo_frame_capable": {
Type: schema.TypeBool,
Computed: true,
},
"tags": tagsSchema(),
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Update: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
},
}
Expand All @@ -111,6 +122,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) != "" {
Expand Down Expand Up @@ -145,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
}

Expand Down Expand Up @@ -175,6 +187,8 @@ 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)
d.Set("jumbo_frame_capable", vif.JumboFrameCapable)
if err := getTagsDX(conn, d, d.Get("arn").(string)); err != nil {
return err
}
Expand All @@ -187,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)
}

Expand All @@ -207,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,
},
Expand Down
64 changes: 64 additions & 0 deletions aws/resource_aws_dx_private_virtual_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,49 @@ 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),
resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "mtu", "1500"),
resource.TestCheckResourceAttr("aws_dx_private_virtual_interface.foo", "jumbo_frame_capable", "true"),
),
},
{
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"),
),
},
{
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"),
),
},
},
})
}

func testAccCheckAwsDxPrivateVirtualInterfaceDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).dxconn

Expand Down Expand Up @@ -177,3 +220,24 @@ resource "aws_dx_private_virtual_interface" "foo" {
}
`, n, amzAsn, cid, n, bgpAsn)
}

func testAccDxPrivateVirtualInterfaceConfig_jumboFrames(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)
}
7 changes: 4 additions & 3 deletions aws/resource_aws_dx_public_virtual_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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,
},
Expand Down
19 changes: 19 additions & 0 deletions aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,25 @@ func validateCloudWatchLogResourcePolicyDocument(v interface{}, k string) (ws []
return
}

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 {
Expand Down
50 changes: 50 additions & 0 deletions aws/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,56 @@ func TestValidateS3BucketLifecycleTimestamp(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
Expand Down
Loading