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

[FIX] Zone Auth setting NSGroup as None after importing #351

Merged
Merged
Changes from all commits
Commits
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
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
Loading