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: allow permissions constraint to be nullable #30

Merged
merged 1 commit into from
Jul 20, 2023
Merged

fix: allow permissions constraint to be nullable #30

merged 1 commit into from
Jul 20, 2023

Conversation

tagur87
Copy link

@tagur87 tagur87 commented 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

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
@tagur87
Copy link
Author

tagur87 commented Jul 20, 2023

@fbreckle - need this for the associated fix for the TF provider

tagur87 added a commit to tagur87/terraform-provider-netbox that referenced this pull request Jul 20, 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 merged commit dd0b7c4 into fbreckle:master Jul 20, 2023
@tagur87 tagur87 deleted the permission-constraint-null branch July 20, 2023 15:46
tagur87 added a commit to tagur87/terraform-provider-netbox that referenced this pull request Jul 20, 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.

Updates to latest fbreckle/go-netbox to support the change.
fbreckle added a commit to e-breuninger/terraform-provider-netbox that referenced this pull request Jul 20, 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 <[email protected]>
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 <[email protected]>
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