databricks_alert Resource
June 12, 2026 ยท View on GitHub
This resource allows you to manage Databricks SQL Alerts. It supersedes databricks_sql_alert resource - see migration guide below for more details.
-> This resource can only be used with a workspace-level provider!
Example Usage
resource "databricks_directory" "shared_dir" {
path = "/Shared/Queries"
}
# This will be replaced with new databricks_query resource
resource "databricks_query" "this" {
warehouse_id = databricks_sql_endpoint.example.id
display_name = "My Query Name"
query_text = "SELECT 42 as value"
parent_path = databricks_directory.shared_dir.path
}
resource "databricks_alert" "alert" {
query_id = databricks_query.this.id
display_name = "TF new alert"
parent_path = databricks_directory.shared_dir.path
condition {
op = "GREATER_THAN"
operand {
column {
name = "value"
}
}
threshold {
value {
double_value = 42
}
}
}
}
Argument Reference
The following arguments are available:
query_id- (Required, String) ID of the query evaluated by the alert.display_name- (Required, String) Name of the alert.condition- (Required) Trigger conditions of the alert. Block consists of the following attributes:op- (Required, String Enum) Operator used for comparison in alert evaluation. (Enum:GREATER_THAN,GREATER_THAN_OR_EQUAL,LESS_THAN,LESS_THAN_OR_EQUAL,EQUAL,NOT_EQUAL,IS_NULL)operand- (Required, Block) Name of the column from the query result to use for comparison in alert evaluation:column- (Required, Block) Block describing the column from the query result to use for comparison in alert evaluation:name- (Required, String) Name of the column.
threshold- (Optional forIS_NULLoperation, Block) Threshold value used for comparison in alert evaluation:value- (Required, Block) actual value used in comparison (one of the attributes is required):string_value- string value to compare against string results.double_value- double value to compare against integer and double results.bool_value- boolean value (trueorfalse) to compare against boolean results.
empty_result_state- (Optional, String Enum) Alert state if the result is empty (UNKNOWN,OK,TRIGGERED)
custom_subject- (Optional, String) Custom subject of alert notification, if it exists. This includes email subject, Slack notification header, etc. See Alerts API reference for custom templating instructions.custom_body- (Optional, String) Custom body of alert notification, if it exists. See Alerts API reference for custom templating instructions.parent_path- (Optional, String) The path to a workspace folder containing the alert. The default is the user's home folder. If changed, the alert will be recreated.seconds_to_retrigger- (Optional, Integer) Number of seconds an alert must wait after being triggered to rearm itself. After rearming, it can be triggered again. If 0 or not specified, the alert will not be triggered again.owner_user_name- (Optional, String) Alert owner's username.notify_on_ok- (Optional, Boolean) Whether to notify alert subscribers when alert returns back to normal.provider_config- (Optional) Configure the provider for management through account provider. This block consists of the following fields:workspace_id- (Required) Workspace ID which the resource belongs to. This workspace must be part of the account which the provider is configured with.
Attribute Reference
In addition to all the arguments above, the following attributes are exported:
id- unique ID of the Alert.lifecycle_state- The workspace state of the alert. Used for tracking trashed status. (Possible values areACTIVEorTRASHED).state- Current state of the alert's trigger status (UNKNOWN,OK,TRIGGERED). This field is set toUNKNOWNif the alert has not yet been evaluated or ran into an error during the last evaluation.create_time- The timestamp string indicating when the alert was created.update_time- The timestamp string indicating when the alert was updated.trigger_time- The timestamp string when the alert was last triggered if the alert has been triggered before.
Migrating from databricks_sql_alert resource
Under the hood, the new resource uses the same data as the databricks_sql_alert, but is exposed via a different API. This means that we can migrate existing alerts without recreating them.
-> It's also recommended to migrate to the databricks_query resource - see databricks_query for more details.
This operation is done in few steps:
- Record the ID of existing
databricks_sql_alert, for example, by executing theterraform state show databricks_sql_alert.alertcommand. - Create the code for the new implementation by performing the following changes:
- the
nameattribute is now nameddisplay_name - the
parent(if exists) is renamed toparent_pathattribute and should be converted fromfolders/object_idto the actual path. - the
optionsblock is converted into theconditionblock with the following changes:- the value of the
opattribute should be converted from a mathematical operator into a string name, like,>is becomingGREATER_THAN,==is becomingEQUAL, etc. - the
columnattribute is becoming theoperandblock - the
valueattribute is becoming thethresholdblock. Please note that the old implementation always used strings so you may have changes after import if you usedouble_valueorbool_valueinside the block.
- the value of the
- the
rearmattribute is renamed toseconds_to_retrigger.
- the
For example, if we have the original databricks_sql_alert defined as:
resource "databricks_sql_alert" "alert" {
query_id = databricks_sql_query.this.id
name = "My Alert"
parent = "folders/${databricks_directory.shared_dir.object_id}"
options {
column = "value"
op = ">"
value = "42"
muted = false
}
}
we'll have a new resource defined as:
resource "databricks_alert" "alert" {
query_id = databricks_query.this.id
display_name = "My Alert"
parent_path = databricks_directory.shared_dir.path
condition {
op = "GREATER_THAN"
operand {
column {
name = "value"
}
}
threshold {
value {
double_value = 42
}
}
}
}
For Terraform version >= 1.7.0
Terraform 1.7 introduced the removed block in addition to the import block introduced in Terraform 1.5. Together they make import and removal of resources easier, avoiding manual execution of terraform import and terraform state rm commands.
So with Terraform 1.7+, the migration looks as the following:
- remove the old alert definition and replace it with the new one.
- Adjust references, like,
databricks_permissions. - Add
importandremovedblocks like this:
import {
to = databricks_alert.alert
id = "<alert-id>"
}
removed {
from = databricks_sql_alert.alert
lifecycle {
destroy = false
}
}
- Run the
terraform plancommand to check possible changes, such as value type change, etc. - Run the
terraform applycommand to apply changes. - Remove the
importandremovedblocks from the code.
For Terraform version < 1.7.0
- Remove the old alert definition and replace it with the new one.
- Remove the old resource from the state with the
terraform state rm databricks_sql_alert.alertcommand. - Import new resource with the
terraform import databricks_alert.alert <alert-id>command. - Adjust references, like,
databricks_permissions. - Run the
terraform plancommand to check possible changes, such as value type change, etc.
Access Control
databricks_permissions can control which groups or individual users can Manage, Edit, Run or View individual alerts.
resource "databricks_permissions" "alert_usage" {
sql_alert_id = databricks_alert.alert.id
access_control {
group_name = "users"
permission_level = "CAN_RUN"
}
}
Access Control
databricks_permissions can control which groups or individual users can Manage, Edit, Run or View individual alerts.
resource "databricks_permissions" "alert_usage" {
sql_alert_id = databricks_alert.alert.id
access_control {
group_name = "users"
permission_level = "CAN_RUN"
}
}
Import
This resource can be imported using alert ID:
import {
to = databricks_alert.this
id = "<alert-id>"
}
Alternatively, when using terraform version 1.4 or earlier, import using the terraform import command:
terraform import databricks_alert.this <alert-id>
Related Resources
The following resources are often used in the same context:
- databricks_query to manage Databricks SQL Queries.
- databricks_sql_endpoint to manage Databricks SQL Endpoints.
- databricks_directory to manage directories in Databricks Workpace.