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 #1

Merged
merged 6 commits into from
Dec 26, 2024

Conversation

xabinapal
Copy link
Owner

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 e-breuninger#242 and e-breuninger#632. This change should resolve the permanent diff behaviour in the tests of those PRs.

Signed-off-by: Xabier Napal <xabier.napal@dvzr.io>
Signed-off-by: Xabier Napal <xabier.napal@dvzr.io>
Signed-off-by: Xabier Napal <xabier.napal@dvzr.io>
Signed-off-by: Xabier Napal <xabier.napal@dvzr.io>
Signed-off-by: Xabier Napal <xabier.napal@dvzr.io>
Signed-off-by: Xabier Napal <xabier.napal@dvzr.io>
@xabinapal xabinapal merged commit 3a975fb into releases Dec 26, 2024
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.

None yet

1 participant