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: netbox_permission plan constraint diff #432

Merged
merged 2 commits into from
Jul 20, 2023

Conversation

tagur87
Copy link
Contributor

@tagur87 tagur87 commented Jul 19, 2023

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.

@fbreckle fbreckle marked this pull request as draft July 19, 2023 19:39
@tagur87 tagur87 force-pushed the permission-constraint-null branch from c25817f to 5419e78 Compare July 20, 2023 15:35
fbreckle pushed a commit to fbreckle/go-netbox that referenced this pull request Jul 20, 2023
With the current configuration, if we pass a null value to clear the
constraint field and make it null, the field is ommitted and thus no
changes are made.

With this change, we update the field to remove omitempty, which
allows us to send a null value to the field, thus clearing it when
it's empty.

Critical part of the fix here:
e-breuninger/terraform-provider-netbox#432
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.

Updates to latest fbreckle/go-netbox to support the change.
@tagur87 tagur87 force-pushed the permission-constraint-null branch from 5419e78 to 93b7dec Compare July 20, 2023 15:51
@tagur87 tagur87 marked this pull request as ready for review July 20, 2023 16:07
@tagur87
Copy link
Contributor Author

tagur87 commented Jul 20, 2023

@fbreckle - ready

@fbreckle
Copy link
Collaborator

fbreckle commented Jul 20, 2023

I took the liberty to add test that fails without your commit to verify that it solves the issue.

@fbreckle fbreckle merged commit b8f284c into e-breuninger:master Jul 20, 2023
twink0r pushed a commit to twink0r/terraform-provider-netbox that referenced this pull request Sep 15, 2023
* fix: netbox_permission plan constraint diff

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.

Updates to latest fbreckle/go-netbox to support the change.

* test: Add test for permission resource without constraint

---------

Co-authored-by: Fabian Breckle <fabian.breckle@breuninger.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants