Skip to content

Commit

Permalink
[FIX] Zone Auth setting NSGroup as None after importing (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
JkhatriInfobox authored Jun 4, 2024
1 parent 42926a0 commit b9b9504
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions infoblox/resource_infoblox_zone_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
Expand Down

0 comments on commit b9b9504

Please sign in to comment.