From b9b95048b0c3fa6c4e5fad9a40bfdfe5338f0eee Mon Sep 17 00:00:00 2001 From: Jeenitkumar Khatri <58591067+JkhatriInfobox@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:23:47 +0530 Subject: [PATCH] [FIX] Zone Auth setting NSGroup as None after importing (#351) --- infoblox/resource_infoblox_zone_auth.go | 39 +++++++++++++++++-------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/infoblox/resource_infoblox_zone_auth.go b/infoblox/resource_infoblox_zone_auth.go index 6149739eb..d4ae72988 100644 --- a/infoblox/resource_infoblox_zone_auth.go +++ b/infoblox/resource_infoblox_zone_auth.go @@ -182,13 +182,11 @@ func formZone( zone.Comment = utils.StringPtr(d.Get("comment").(string)) } - if d.HasChange("ns_group") { - nsGrp := d.Get("ns_group").(string) - if nsGrp != "" { - zone.NsGroup = utils.StringPtr(nsGrp) - } else { - zone.NsGroup = nil - } + nsGrp := d.Get("ns_group").(string) + if nsGrp != "" { + zone.NsGroup = utils.StringPtr(nsGrp) + } else { + zone.NsGroup = nil } if d.HasChange("restart_if_needed") { @@ -295,9 +293,11 @@ func resourceZoneAuthRead(ctx context.Context, d *schema.ResourceData, m interfa if zoneResult.NsGroup != nil { err = d.Set("ns_group", *zoneResult.NsGroup) - if err != nil { - return diag.FromErr(err) - } + } else { + err = d.Set("ns_group", "") + } + if err != nil { + return diag.FromErr(err) } if zoneResult.SoaDefaultTtl != nil { @@ -404,8 +404,23 @@ func resourceZoneAuthUpdate(ctx context.Context, d *schema.ResourceData, m inter } connector := m.(ibclient.IBConnector) - objMgr := ibclient.NewObjectManager(connector, "Terraform", "terraform_test_tenant") - zoneVal, err := objMgr.GetZoneAuthByRef(d.Id()) + + rec, err := searchObjectByRefOrInternalId("ZoneAuth", d, m) + if err != nil { + if _, ok := err.(*ibclient.NotFoundError); !ok { + return diag.FromErr(ibclient.NewNotFoundError(fmt.Sprintf( + "cannot find appropriate object on NIOS side for resource with ID '%s': %s;", d.Id(), err))) + } else { + d.SetId("") + return nil + } + } + + // Assertion of object type and error handling + var zoneVal *ibclient.ZoneAuth + recJson, _ := json.Marshal(rec) + err = json.Unmarshal(recJson, &zoneVal) + if err != nil { return diag.FromErr(fmt.Errorf("failed to read Zone Auth for update operation: %w", err)) }