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(resources): improve custom_field attribute handling to avoid permanent diffs #667

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

xabinapal
Copy link

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
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.

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.

1 participant