Skip to content

direct: reject variable references in resource map keys#5164

Open
SAY-5 wants to merge 1 commit intodatabricks:mainfrom
SAY-5:fix/schema-variable-ref-panic-5098
Open

direct: reject variable references in resource map keys#5164
SAY-5 wants to merge 1 commit intodatabricks:mainfrom
SAY-5:fix/schema-variable-ref-panic-5098

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 3, 2026

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 in bundle/direct/bundle_plan.go. The string is then re-parsed by dyn.NewPathFromString, which splits on . and produces a non-existent path. Root.GetResourceConfig returns (nil, nil) for that path, and the resulting nil *resources.Schema is dereferenced inside PrepareState (bundle/direct/dresources/schema.go:22), panicking with a nil pointer.

This change detects variable references in resource map keys during the MapByPattern walk in makePlan and 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.md rules "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

  • New regression test TestMakePlanRejectsVariableInResourceKey in bundle/direct/bundle_plan_test.go reproduces 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:22 nil deref); with the fix it returns resource 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 120s passes (unrelated TestClearWorkspaceClient requires ~/.databrickscfg and fails on main too).

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>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

An authorized user can trigger integration tests manually by following the instructions below:

Trigger:
go/deco-tests-run/cli

Inputs:

  • PR number: 5164
  • Commit SHA: a99e58637bb4fdce1cdbbbe226ad00dfe23f1fc6

Checks will be approved automatically on success.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

Waiting for approval

Based on git history, these people are best suited to review:

  • @denik -- recent work in bundle/direct/

Eligible reviewers: @andrewnester, @anton-107, @janniklasrose, @lennartkats-db, @pietern, @shreyas-goenka

Suggestions based on git history. See OWNERS for ownership rules.

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.

CLI Panics when referencing variable in resources.schema.<schema>

1 participant