From 2fd2c0af446a691d6b86a5d4e2d3c17a6919da63 Mon Sep 17 00:00:00 2001 From: Dimitrios Karagiannis Date: Tue, 29 Oct 2019 00:01:50 +0000 Subject: [PATCH] Extend error handling These should not return errors under normal circumstances but they can and we should return that to the caller. Signed-off-by: Dimitrios Karagiannis --- megaport/resource_megaport_aws_vxc.go | 16 +++++++++---- megaport/resource_megaport_port.go | 28 +++++++++++++++++------ megaport/resource_megaport_private_vxc.go | 20 ++++++++++++---- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/megaport/resource_megaport_aws_vxc.go b/megaport/resource_megaport_aws_vxc.go index 0911ef0..d9bafb5 100644 --- a/megaport/resource_megaport_aws_vxc.go +++ b/megaport/resource_megaport_aws_vxc.go @@ -95,13 +95,21 @@ func resourceMegaportAwsVxcRead(d *schema.ResourceData, m interface{}) error { d.SetId("") return nil } - d.Set("name", p.ProductName) - d.Set("rate_limit", p.RateLimit) - d.Set("a_end", flattenVxcEnd(p.AEnd)) + if err := d.Set("name", p.ProductName); err != nil { + return err + } + if err := d.Set("rate_limit", p.RateLimit); err != nil { + return err + } + if err := d.Set("a_end", flattenVxcEnd(p.AEnd)); err != nil { + return err + } if err := d.Set("b_end", flattenVxcEndAws(p.BEnd, p.Resources)); err != nil { return err } - d.Set("invoice_reference", p.CostCentre) + if err := d.Set("invoice_reference", p.CostCentre); err != nil { + return err + } return nil } diff --git a/megaport/resource_megaport_port.go b/megaport/resource_megaport_port.go index 4295d3e..5f8a2c7 100644 --- a/megaport/resource_megaport_port.go +++ b/megaport/resource_megaport_port.go @@ -77,14 +77,28 @@ func resourceMegaportPortRead(d *schema.ResourceData, m interface{}) error { d.SetId("") return nil } - d.Set("location_id", p.LocationId) - d.Set("name", p.ProductName) - d.Set("speed", p.PortSpeed) - d.Set("term", p.ContractTermMonths) - d.Set("associated_vxcs", schema.NewSet(schema.HashResource(resourceMegaportPrivateVxc()), flattenVxcList(p.AssociatedVxcs))) - d.Set("marketplace_visibility", "private") + if err := d.Set("location_id", p.LocationId); err != nil { + return err + } + if err := d.Set("name", p.ProductName); err != nil { + return err + } + if err := d.Set("speed", p.PortSpeed); err != nil { + return err + } + if err := d.Set("term", p.ContractTermMonths); err != nil { + return err + } + if err := d.Set("associated_vxcs", schema.NewSet(schema.HashResource(resourceMegaportPrivateVxc()), flattenVxcList(p.AssociatedVxcs))); err != nil { + return err + } + if err := d.Set("marketplace_visibility", "private"); err != nil { + return err + } if p.MarketplaceVisibility { - d.Set("marketplace_visibility", "public") + if err := d.Set("marketplace_visibility", "public"); err != nil { + return err + } } //d.Set("invoice_reference", p.) // TODO: is this even exported? return nil diff --git a/megaport/resource_megaport_private_vxc.go b/megaport/resource_megaport_private_vxc.go index 7d0397c..2103409 100644 --- a/megaport/resource_megaport_private_vxc.go +++ b/megaport/resource_megaport_private_vxc.go @@ -59,11 +59,21 @@ func resourceMegaportPrivateVxcRead(d *schema.ResourceData, m interface{}) error d.SetId("") return nil } - d.Set("name", p.ProductName) - d.Set("rate_limit", p.RateLimit) - d.Set("a_end", flattenVxcEnd(p.AEnd)) - d.Set("b_end", flattenVxcEnd(p.BEnd)) - d.Set("invoice_reference", p.CostCentre) + if err := d.Set("name", p.ProductName); err != nil { + return err + } + if err := d.Set("rate_limit", p.RateLimit); err != nil { + return err + } + if err := d.Set("a_end", flattenVxcEnd(p.AEnd)); err != nil { + return err + } + if err := d.Set("b_end", flattenVxcEnd(p.BEnd)); err != nil { + return err + } + if err := d.Set("invoice_reference", p.CostCentre); err != nil { + return err + } return nil }