Skip to content

Support referencing an external .sql file for query_text in resources.alerts #5620

@tuterbatuhan

Description

@tuterbatuhan

Summary

Databricks Asset Bundles allow defining alerts-v2 via resources.alerts, but query_text must be inline YAML. There is no native way to source the alert SQL from an external .sql file. Requesting a supported file-include for query_text (or a documented .sql reference analogous to the existing .dbalert.json support).

Motivation / customer context

This comes from a customer (enterprise, EU) managing alerts-v2 as code. Their alert queries are multi-line SQL, and keeping that SQL inline in YAML is hard to maintain, review, and lint. They want the SQL to live in its own .sql file (single source of truth, normal SQL tooling), the same way job sql_task steps can reference a .sql file via file.path.

Current behavior

query_text: ${file("../sql/alert_query.sql")} validates fine but resolves to the literal string ${file(...)}, deploying a broken query. There is no file() include function for this field.

Bundles today allow referencing a .dbalert.json file (as committed from the web UI), but not a standalone .sql file.

Workaround (works, but glue)

Declare a variable and inject the file contents at deploy time via an env var:

export BUNDLE_VAR_alert_query="$(cat sql/alert_query.sql)"
databricks bundle deploy
variables:
  alert_query:
    default: ""
resources:
  alerts:
    failed_pipeline_runs:
      query_text: ${var.alert_query}

Note: --var="alert_query=$(cat ...)" does not work. Multi-line --var values are truncated at the first newline; only the BUNDLE_VAR_ env var preserves the whole file.

Proposed solution

Support a native file reference for query_text, e.g. either:

  • a file()-style include that interpolates file contents into the string field, or
  • a query_file/file.path style attribute on the alert resource, mirroring how sql_task references .sql files.

Environment

  • Databricks CLI: 0.297.2 (also reproduced on 0.281.0)
  • alerts-v2 resource (resources.alerts)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions