fix: preserve empty list vs null for optional list attributes #1

Merged
benvin merged 1 commits from benvin/fix-empty-list-null-inconsistency into main 2026-06-21 18:51:32 +10:00
Owner

Summary

  • Fixed "inconsistent result after apply" errors caused by the provider returning null for optional list fields (mutable_patterns, ban_tags, etc.) when the plan had an empty list []
  • stringsToList now distinguishes nil (→ null) from []string{} (→ empty list)
  • Added preserveListNullEmptySemantics helper and reconcileOptionalLists called in Create, Update, and Read to handle the API returning null for empty arrays

Test plan

  • All existing unit tests pass
  • New TestPreserveListNullEmptySemantics covers all four null/empty combinations
  • Updated TestStringsToList_EmptySlice to verify new empty-list-not-null behavior
  • Deploy and run terragrunt apply against artifactapi3 to confirm no more inconsistent result errors
## Summary - Fixed "inconsistent result after apply" errors caused by the provider returning `null` for optional list fields (`mutable_patterns`, `ban_tags`, etc.) when the plan had an empty list `[]` - `stringsToList` now distinguishes `nil` (→ null) from `[]string{}` (→ empty list) - Added `preserveListNullEmptySemantics` helper and `reconcileOptionalLists` called in Create, Update, and Read to handle the API returning null for empty arrays ## Test plan - [x] All existing unit tests pass - [x] New `TestPreserveListNullEmptySemantics` covers all four null/empty combinations - [x] Updated `TestStringsToList_EmptySlice` to verify new empty-list-not-null behavior - [ ] Deploy and run `terragrunt apply` against artifactapi3 to confirm no more inconsistent result errors
unkinben added 1 commit 2026-06-21 18:43:41 +10:00
fix: preserve empty list vs null distinction for optional list attributes
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
d9d8cc7b6d
The API returns null for empty arrays, but OpenTofu requires that the
state match the plan exactly — an empty list [] in the plan must remain
[] in the state, not become null. This caused "inconsistent result after
apply" errors on every resource with empty optional list fields like
mutable_patterns and ban_tags.
benvin merged commit a626d29aff into main 2026-06-21 18:51:32 +10:00
benvin deleted branch benvin/fix-empty-list-null-inconsistency 2026-06-21 18:51:32 +10:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: unkin/terraform-provider-artifactapi#1