Skip to content

Conversation

@xabinapal
Copy link
Contributor

This pull request improves the handling of the custom_fields attribute present in many resources. The NetBox API always returns all custom fields for a particular object, whether they are set or not, with unset fields being represented as nulls or empty strings.

Currently, this behavior causes permanent differences in execution plans if users do not specify all custom fields, even when only some of them have values. This is common when adding a new custom field to an object that is already managed in Terraform. All the resources created will then have a difference unless the user includes the new custom field in the resource definition, even if they don't want to set a value for it.

To address this, the custom_fields attribute has been marked as Computed, allowing it to be modified internally. A CustomizeDiff function has been added to the schema of all resources using custom fields to manage the internal state of this attribute effectively and identify real differences and fake ones.

Also, this issue has been noticed before in some open pull requests, including #242 and #632. This change should resolve the permanent diff behaviour in the tests of those PRs.

@xabinapal
Copy link
Contributor Author

There are two unrelated (but required) changes in this PR:

  • The custom_fields attribute in custom_field_choice_set resource has been removed, as it was not used and does not really exist in Netbox.
  • The same attribute has been added available_prefix resource, due to it's dependency with the prefix resource, which already has this attribute.

@mattwilder
Copy link

Friendly ping. Are there plans to merge this any time soon? We really need this bug fixed for our use of the netbox provider to function correctly.

@NikolaiBessonov
Copy link

Hi! 👋
Thanks a lot for your work on this PR.
We’re really looking forward to this fix — it would help us a lot.

Do you have any plans to merge it soon?

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.

3 participants