fix: handle null values in optional fields to prevent value conversion errors #61
+222
−77
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #60
Summary
This PR fixes value conversion errors that occur when the Entitle API returns null values for optional fields like
integration
,workflow
,allowed_durations
, andmaintainers
. The provider now properly handles null values and prevents drift detection when these fields are null in both the configuration and API response.Changes
Integration
andWorkflow
fields to pointer types (*utils.IdNameModel
) to handle null valuesconvertFullResourceResultResponseSchemaToModel
function to preserve null values forallowed_durations
andmaintainers
instead of converting them to empty arraysUseStateForUnknown()
plan modifiers to computedname
fields within integration and workflow nested attributes to prevent drift on read-only fieldsComputed: true
fromallowed_durations
andmaintainers
schema - having bothOptional
andComputed
caused value conversion errors during updatesOwner
andWorkflow
pointers when populated - prevents 404 errors from API when sending empty structsTestResourceResourceNullFields
acceptance test to verify null handling behaviorTesting
TestResourceResourceNullFields
that:terraform plan
shows "No changes" after importrequestable
field updates (true ↔ false)Technical Details
The root cause was that non-pointer struct types in Go cannot represent null values. When the API returned null for optional nested objects like
integration
orworkflow
, the Terraform Plugin Framework couldn't convert these null values to the non-nullableutils.IdNameModel
struct type.Additionally, optional fields marked as
Computed: true
caused Terraform to treat them as "unknown" during update operations, leading to "Value Conversion Error" when trying to convert unknown values to Go slice types.The fix:
Integration
andWorkflow
fields to pointer types with comprehensive nil checksComputed: true
from optional list/set fields to prevent unknown value errors🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]