direct: reject variable references in resource map keys#5164
Open
SAY-5 wants to merge 1 commit intodatabricks:mainfrom
Open
direct: reject variable references in resource map keys#5164SAY-5 wants to merge 1 commit intodatabricks:mainfrom
SAY-5 wants to merge 1 commit intodatabricks:mainfrom
Conversation
Variable references in resource map keys (e.g. resources.schemas.${var.schema})
are not resolvable at plan time and the literal '${var.foo}' string is
re-parsed via dyn.NewPathFromString, which splits on '.' and produces a
non-existent path. GetResourceConfig then returns (nil, nil), and the nil
*resources.Schema is dereferenced inside PrepareState, panicking with a
nil pointer.
Detect variable references in the resource key during the plan walk and
return an actionable error. Fixes databricks#5098.
Signed-off-by: SAY-5 <say.apm35@gmail.com>
|
An authorized user can trigger integration tests manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
Waiting for approvalBased on git history, these people are best suited to review:
Eligible reviewers: Suggestions based on git history. See OWNERS for ownership rules. |
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.
Changes
When a resource is keyed by a variable reference (e.g.
resources.schemas.${var.schema}), the literal${var.foo}survives the plan-time walk inbundle/direct/bundle_plan.go. The string is then re-parsed bydyn.NewPathFromString, which splits on.and produces a non-existent path.Root.GetResourceConfigreturns(nil, nil)for that path, and the resulting nil*resources.Schemais dereferenced insidePrepareState(bundle/direct/dresources/schema.go:22), panicking with a nil pointer.This change detects variable references in resource map keys during the
MapByPatternwalk inmakePlanand returns an actionable error instead of crashing.Why
Closes #5098. The user expected either correct interpolation or a clear error; either way, panicking is wrong. Variable interpolation only applies to values, not to map keys, so the only correct behavior here is a validation error pointing at the offending key. Matches the
CLAUDE.mdrules "Reject incompatible inputs early with an actionable error" and "Where a panic is genuinely possible, validate at the entry point and return an error."Tests
TestMakePlanRejectsVariableInResourceKeyinbundle/direct/bundle_plan_test.goreproduces the issue's YAML scenario and asserts a clear error message instead of a panic. Without the fix, this test panics with the exact stack trace from the issue (schema.go:22nil deref); with the fix it returnsresource key "resources.schemas.${var.schema}" cannot contain variable references; use a literal key and parameterize fields like 'name' instead.go build ./...go test ./bundle/... -timeout 120spasses (unrelatedTestClearWorkspaceClientrequires~/.databrickscfgand fails onmaintoo).