Skip to content

Commit

Permalink
fix: netbox_permission plan constraint diff
Browse files Browse the repository at this point in the history
Every run of the `netbox_permission` resource when there was no
constraint set would output the following diff:
```
netbox_permission.ipaddress_rw_permission will be updated in-place
  ~ resource "netbox_permission" "ipaddress_rw_permission" {
      - constraints  = "null" -> null
        id           = "3"
        name         = "ipaddress_rw_permissions"
```

There are inherently two issues that cause the problem. We cannot null
the field, because of the issue fixed here:
fbreckle/go-netbox#30

Second, want the constraint field to be set to an empty string when
a read of constraint is empty. So we check if nil, and if so we
set constraint to "", and then return the function. Otherwise, we
Marshal it to JSON to fill the tf state.
  • Loading branch information
tagur87 committed Jul 20, 2023
1 parent 39ce3e2 commit 5419e78
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion netbox/resource_netbox_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func resourceNetboxPermission() *schema.Resource {
Description: "A JSON string of an arbitrary filter used to limit the granted action(s) to a specific subset of objects. " +
"For more information on correct syntax, see https://docs.netbox.dev/en/stable/administration/permissions/#constraints ",
Optional: true,
Default: nil,
ValidateFunc: validation.StringIsJSON,
},
},
Expand Down Expand Up @@ -165,6 +164,11 @@ func resourceNetboxPermissionRead(d *schema.ResourceData, m interface{}) error {

d.Set("actions", res.GetPayload().Actions)

if res.GetPayload().Constraints == nil {
d.Set("constraints", "")
return nil
}

b, err := json.Marshal(res.GetPayload().Constraints)
if err != nil {
return err
Expand Down

0 comments on commit 5419e78

Please sign in to comment.