Fix opslevel_filter nil-pointer panic reading case_sensitive when API…#659
Open
saditya370 wants to merge 1 commit into
Open
Fix opslevel_filter nil-pointer panic reading case_sensitive when API…#659saditya370 wants to merge 1 commit into
saditya370 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves OpsLevel ticket #15041. Re-lands approved PR #653 (closed by the reporter after they worked around it locally, so the fix was never merged).
Problem
terraform planpanics with a nil-pointer dereference when reading anyopslevel_filterwhose Terraform state holds acase_sensitive(orcase_insensitive) value for a predicate that the OpsLevel API returns asnil— e.g.exists,matchesagainst an ID, and other predicate types that don't take a case-sensitivity argument.NewFilterResourceModelonly checked whether state had a value, then unconditionally dereferenced the API predicate'sCaseSensitive(*bool). For predicate types with no case sensitivity the API returnsnil, so the deref panics. This blocks all filter operations for workspaces upgrading from provider 0.8.x, whose schema storedcase_sensitiveon every predicate regardless of type — the firstterraform planafter upgrade crashes.Solution
Guard both branches with
opslevelPredicate.CaseSensitive != nil. When the API returnsnil, the field normalizes totypes.BoolNull()(unset), which is correct:nilfrom the API means the predicate type has no case-sensitivity concept. This mirrors the guard already present inExtractFilterPredicateModel, and state converges to null with no perpetual drift (config can't setcase_sensitiveon those types anyway — the SDK'svalidateCaseSensitivityrejects it).Added regression tests covering: state has
case_sensitive+ API returnsnil(must not crash, result null); the symmetriccase_insensitivebranch; the happy path where the API sets the value (preserved); and fresh import with a nil API value. The crash test panics atresource_opslevel_filter.go:116before the fix and passes after.Checklist