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_hosted_private_virtual_interface: Update resource to support MTU param #6142

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5298e48
resource/aws_dx_private_virtual_interface: Update resource to support…
slapula Oct 13, 2018
d549990
fixing mtu int handling
slapula Oct 13, 2018
8b4ed89
resource/aws_dx_hosted_private_virtual_interface: Update resource to …
slapula Oct 13, 2018
b5f9c82
exporting value of jumbo frames param
slapula Oct 13, 2018
6282f06
exporting value of jumbo frames param
slapula Oct 13, 2018
cdecb24
adding acc test for mtu
slapula Oct 13, 2018
4b3d2f0
correcting exported value name
slapula Oct 13, 2018
7a1f9b8
adding acc test for mtu
slapula Oct 13, 2018
c4593cc
setting default for mtu
slapula Oct 13, 2018
c6c438e
setting default for mtu
slapula Oct 13, 2018
636db33
validating mtu input & adding expanding vif update function
slapula Oct 15, 2018
257a94a
adding acc test for updating mtu
slapula Oct 15, 2018
4cff326
'IntInSlice' -> 'validateIntegerInSlice'.
ewbankkit Oct 21, 2018
0cf60ab
Add Update timeout to r/aws_dx_private_virtual_interface.
ewbankkit Oct 21, 2018
83b25df
Merge branch 'master' into slapula-dx-private-virtual-interface-mtu
ewbankkit Oct 21, 2018
bd5798b
pulling in ewbankkit changes
slapula Oct 22, 2018
1d75428
forgot a missing file from previous commit
slapula Oct 22, 2018
6f8738b
Merge branch 'master' into dx-private-virtual-interface-mtu
slapula Oct 22, 2018
1e6b61a
fixing merge conflict
slapula Oct 22, 2018
77e465a
removing conflict cruft
slapula Oct 22, 2018
da69517
changing 1 to true
slapula Oct 23, 2018
ad2ce09
Merge branch 'master' into dx-hosted-private-virtual-interfarce-mtu
slapula Oct 23, 2018
2478fba
adding improvements from dx-private-virtual-interfarce-mtu branch
slapula Oct 23, 2018
2aa7a45
Merge remote-tracking branch 'slapula/dx-private-virtual-interface-mt…
Oct 23, 2018
0089b9f
Fix typos in acceptance tests.
Oct 23, 2018
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 {
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
25 changes: 22 additions & 3 deletions aws/resource_aws_dx_hosted_private_virtual_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,22 @@ func resourceAwsDxHostedPrivateVirtualInterface() *schema.Resource {
ForceNew: true,
ValidateFunc: validateAwsAccountId,
},
"mtu": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a ValidateFunc to ensure that the value is 1500 or 9001.

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

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Update: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
},
}
Expand All @@ -97,6 +109,7 @@ func resourceAwsDxHostedPrivateVirtualInterfaceCreate(d *schema.ResourceData, me
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 v, ok := d.GetOk("bgp_auth_key"); ok && v.(string) != "" {
Expand All @@ -108,6 +121,9 @@ func resourceAwsDxHostedPrivateVirtualInterfaceCreate(d *schema.ResourceData, me
if v, ok := d.GetOk("amazon_address"); ok && v.(string) != "" {
req.NewPrivateVirtualInterfaceAllocation.AmazonAddress = aws.String(v.(string))
}
if v, ok := d.GetOk("mtu"); ok && v.(int) != 0 {
req.NewPrivateVirtualInterfaceAllocation.Mtu = aws.Int64(int64(v.(int)))
}

log.Printf("[DEBUG] Creating Direct Connect hosted private virtual interface: %#v", req)
resp, err := conn.AllocatePrivateVirtualInterface(req)
Expand All @@ -125,7 +141,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 @@ -154,6 +170,8 @@ func resourceAwsDxHostedPrivateVirtualInterfaceRead(d *schema.ResourceData, meta
d.Set("customer_address", vif.CustomerAddress)
d.Set("amazon_address", vif.AmazonAddress)
d.Set("owner_account_id", vif.OwnerAccount)
d.Set("mtu", vif.Mtu)
d.Set("jumbo_frame_capable", vif.JumboFrameCapable)

return nil
}
Expand All @@ -175,10 +193,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
63 changes: 63 additions & 0 deletions aws/resource_aws_dx_hosted_private_virtual_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,54 @@ func TestAccAwsDxHostedPrivateVirtualInterface_basic(t *testing.T) {
})
}

func TestAccAwsDxHostedPrivateVirtualInterface_mtuUpdate(t *testing.T) {
key := "DX_CONNECTION_ID"
connectionId := os.Getenv(key)
if connectionId == "" {
t.Skipf("Environment variable %s is not set", key)
}
key = "DX_HOSTED_VIF_OWNER_ACCOUNT"
ownerAccountId := os.Getenv(key)
if ownerAccountId == "" {
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: testAccCheckAwsDxHostedPrivateVirtualInterfaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccDxHostedPrivateVirtualInterfaceConfig_basic(connectionId, ownerAccountId, vifName, bgpAsn),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsDxHostedPrivateVirtualInterfaceExists("aws_dx_hosted_private_virtual_interface.foo"),
resource.TestCheckResourceAttr("aws_dx_hosted_private_virtual_interface.foo", "name", vifName),
resource.TestCheckResourceAttr("aws_dx_hosted_private_virtual_interface.foo", "mtu", "1500"),
resource.TestCheckResourceAttr("aws_dx_hosted_private_virtual_interface.foo", "jumbo_frame_capable", "true"),
),
},
{
Config: testAccDxHostedPrivateVirtualInterfaceConfig_JumboFrames(connectionId, ownerAccountId, vifName, bgpAsn),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsDxHostedPrivateVirtualInterfaceExists("aws_dx_hosted_private_virtual_interface.foo"),
resource.TestCheckResourceAttr("aws_dx_hosted_private_virtual_interface.foo", "name", vifName),
resource.TestCheckResourceAttr("aws_dx_hosted_private_virtual_interface.foo", "mtu", "9001"),
),
},
{
Config: testAccDxHostedPrivateVirtualInterfaceConfig_basic(connectionId, ownerAccountId, vifName, bgpAsn),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsDxHostedPrivateVirtualInterfaceExists("aws_dx_hosted_private_virtual_interface.foo"),
resource.TestCheckResourceAttr("aws_dx_hosted_private_virtual_interface.foo", "name", vifName),
resource.TestCheckResourceAttr("aws_dx_hosted_private_virtual_interface.foo", "mtu", "1500"),
),
},
},
})
}

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

Expand Down Expand Up @@ -97,3 +145,18 @@ resource "aws_dx_hosted_private_virtual_interface" "foo" {
}
`, cid, ownerAcctId, n, bgpAsn)
}

func testAccDxHostedPrivateVirtualInterfaceConfig_JumboFrames(cid, ownerAcctId, n string, bgpAsn int) string {
return fmt.Sprintf(`
resource "aws_dx_hosted_private_virtual_interface" "foo" {
connection_id = "%s"
owner_account_id = "%s"

name = "%s"
vlan = 4094
address_family = "ipv4"
bgp_asn = %d
mtu = 9001
}
`, cid, ownerAcctId, n, bgpAsn)
}
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": {
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
Loading