Skip to content
This repository has been archived by the owner on Jan 17, 2025. It is now read-only.

Commit

Permalink
megaport_private_vxc: handle optional attributes
Browse files Browse the repository at this point in the history
Optional attributes should not be included to the payload if not set.

Signed-off-by: Dimitrios Karagiannis <dhkarag@gmail.com>
  • Loading branch information
alkar committed Jan 29, 2020
1 parent defb1da commit 066f955
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions megaport/resource_megaport_private_vxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,22 @@ func resourceMegaportPrivateVxcCreate(d *schema.ResourceData, m interface{}) err
cfg := m.(*Config)
a := d.Get("a_end").([]interface{})[0].(map[string]interface{})
b := d.Get("b_end").([]interface{})[0].(map[string]interface{})
uid, err := cfg.Client.CreatePrivateVxc(&api.PrivateVxcCreateInput{
ProductUidA: api.String(a["product_uid"]),
ProductUidB: api.String(b["product_uid"]),
Name: api.String(d.Get("name")),
InvoiceReference: api.String(d.Get("invoice_reference")),
VlanA: api.Uint64FromInt(a["vlan"]),
VlanB: api.Uint64FromInt(b["vlan"]),
RateLimit: api.Uint64FromInt(d.Get("rate_limit")),
})
input := &api.PrivateVxcCreateInput{
ProductUidA: api.String(a["product_uid"]),
ProductUidB: api.String(b["product_uid"]),
Name: api.String(d.Get("name")),
RateLimit: api.Uint64FromInt(d.Get("rate_limit")),
}
if v, ok := d.GetOk("invoice_reference"); ok {
input.InvoiceReference = api.String(v)
}
if v := a["vlan"].(int); v != 0 {
input.VlanA = api.Uint64FromInt(v)
}
if v := b["vlan"].(int); v != 0 {
input.VlanB = api.Uint64FromInt(v)
}
uid, err := cfg.Client.CreatePrivateVxc(input)
if err != nil {
return err
}
Expand All @@ -107,14 +114,18 @@ func resourceMegaportPrivateVxcUpdate(d *schema.ResourceData, m interface{}) err
a := d.Get("a_end").([]interface{})[0].(map[string]interface{})
b := d.Get("b_end").([]interface{})[0].(map[string]interface{})
input := &api.PrivateVxcUpdateInput{
InvoiceReference: api.String(d.Get("invoice_reference")),
Name: api.String(d.Get("name")),
ProductUid: api.String(d.Id()),
RateLimit: api.Uint64FromInt(d.Get("rate_limit")),
VlanA: api.Uint64FromInt(a["vlan"]),
}
if d.HasChange("b_end.0.vlan") {
input.VlanB = api.Uint64FromInt(b["vlan"])
Name: api.String(d.Get("name")),
ProductUid: api.String(d.Id()),
RateLimit: api.Uint64FromInt(d.Get("rate_limit")),
}
if v, ok := d.GetOk("invoice_reference"); ok {
input.InvoiceReference = api.String(v)
}
if v := a["vlan"].(int); v != 0 {
input.VlanA = api.Uint64FromInt(v)
}
if v := b["vlan"].(int); v != 0 {
input.VlanB = api.Uint64FromInt(v)
}
if err := cfg.Client.UpdatePrivateVxc(input); err != nil {
return err
Expand Down

0 comments on commit 066f955

Please sign in to comment.