Skip to content

Commit

Permalink
Fix for NPA-166: inconsistent 'delegated_ttl' value for zone_delegate…
Browse files Browse the repository at this point in the history
…d resource and datasource
  • Loading branch information
Aish-sp committed Sep 19, 2024
1 parent 3aa287a commit 241dd71
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
11 changes: 10 additions & 1 deletion infoblox/datasource_infoblox_zone_delegated.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,18 @@ func flattenZoneDelegated(zoneDelegated ibclient.ZoneDelegated) (map[string]inte
if zoneDelegated.NsGroup != nil {
res["ns_group"] = *zoneDelegated.NsGroup
}
if zoneDelegated.DelegatedTtl != nil {
if zoneDelegated.UseDelegatedTtl != nil {
if !*zoneDelegated.UseDelegatedTtl {
res["delegated_ttl"] = ttlUndef
}
}

if zoneDelegated.DelegatedTtl != nil && *zoneDelegated.DelegatedTtl > 0 {
res["delegated_ttl"] = *zoneDelegated.DelegatedTtl
} else {
res["delegated_ttl"] = ttlUndef
}

if zoneDelegated.DelegateTo.IsNull == false {

Check failure on line 195 in infoblox/datasource_infoblox_zone_delegated.go

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, 1.21)

zoneDelegated.DelegateTo.IsNull undefined (type []ibclient.NameServer has no field or method IsNull)

Check failure on line 195 in infoblox/datasource_infoblox_zone_delegated.go

View workflow job for this annotation

GitHub Actions / Test (macOS-latest, 1.21)

zoneDelegated.DelegateTo.IsNull undefined (type []ibclient.NameServer has no field or method IsNull)
nsInterface := convertNullableNameServersToInterface(zoneDelegated.DelegateTo)
res["delegate_to"] = nsInterface
Expand Down
12 changes: 11 additions & 1 deletion infoblox/resource_infoblox_zone_delegated.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ func resourceZoneDelegatedImport(d *schema.ResourceData, m interface{}) ([]*sche
return nil, err
}

var ttl int
connector := m.(ibclient.IBConnector)
objMgr := ibclient.NewObjectManager(connector, "Terraform", "")

Expand Down Expand Up @@ -546,8 +547,17 @@ func resourceZoneDelegatedImport(d *schema.ResourceData, m interface{}) ([]*sche
}
}

if zoneDelegated.DelegatedTtl != nil && *zoneDelegated.DelegatedTtl > 0 {
ttl = int(*zoneDelegated.DelegatedTtl)
} else {
ttl = ttlUndef
}
if !*zoneDelegated.UseDelegatedTtl {
ttl = ttlUndef
}

if zoneDelegated.DelegatedTtl != nil {
if err = d.Set("delegated_ttl", *zoneDelegated.DelegatedTtl); err != nil {
if err = d.Set("delegated_ttl", ttl); err != nil {
return nil, err
}
}
Expand Down
6 changes: 3 additions & 3 deletions infoblox/resource_infoblox_zone_forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ func validateNameServers(ftSlice []interface{}) ([]ibclient.NameServer, error) {
if err != nil {
return nil, fmt.Errorf("failed to marshal nameservers: %s", err)
}
var forwardTo []ibclient.NameServer
err = json.Unmarshal(nsStr, &forwardTo)
var nameServers []ibclient.NameServer
err = json.Unmarshal(nsStr, &nameServers)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal nameservers: %s", err)
}
return forwardTo, nil
return nameServers, nil
}

func resourceZoneForwardRead(d *schema.ResourceData, m interface{}) error {
Expand Down

0 comments on commit 241dd71

Please sign in to comment.