diff --git a/docs/resources/sql_alert.md b/docs/resources/sql_alert.md index edd918eef7..4f512948c0 100644 --- a/docs/resources/sql_alert.md +++ b/docs/resources/sql_alert.md @@ -50,6 +50,7 @@ The following arguments are available: * `custom_body` - (Optional, String) Custom body of alert notification, if it exists. See [Alerts API reference](https://docs.databricks.com/sql/user/alerts/index.html) for custom templating instructions. * `parent` - (Optional, String) The identifier of the workspace folder containing the alert. The default is ther user's home folder. The folder identifier is formatted as `folder/`. * `rearm` - (Optional, Integer) Number of seconds after being triggered before the alert rearms itself and can be triggered again. If not defined, alert will never be triggered again. +* `empty_result_state` - (Optional, String) State that alert evaluates to when query result is empty. Currently supported values are `unknown`, `triggered`, `ok` - check [API documentation](https://docs.databricks.com/api/workspace/alerts/create) for full list of supported values. ## Related Resources diff --git a/sql/resource_sql_alerts.go b/sql/resource_sql_alerts.go index a7fe04b215..c2cb57970f 100644 --- a/sql/resource_sql_alerts.go +++ b/sql/resource_sql_alerts.go @@ -13,12 +13,13 @@ import ( ) type AlertOptions struct { - Column string `json:"column"` - Op string `json:"op"` - Value string `json:"value"` - Muted bool `json:"muted,omitempty"` - CustomBody string `json:"custom_body,omitempty"` - CustomSubject string `json:"custom_subject,omitempty"` + Column string `json:"column"` + Op string `json:"op"` + Value string `json:"value"` + Muted bool `json:"muted,omitempty"` + CustomBody string `json:"custom_body,omitempty"` + CustomSubject string `json:"custom_subject,omitempty"` + EmptyResultState string `json:"empty_result_state,omitempty"` } type AlertEntity struct { @@ -47,14 +48,18 @@ func (a *AlertEntity) toCreateAlertApiObject(s map[string]*schema.Schema, data * Op: a.Options.Op, Value: a.Options.Value, } - - return ca, nil + // This is a workaround for Go SDK problem, will be fixed there. + var err error + if a.Options.EmptyResultState != "" { + err = ca.Options.EmptyResultState.Set(a.Options.EmptyResultState) + } + return ca, err } func (a *AlertEntity) toEditAlertApiObject(s map[string]*schema.Schema, data *schema.ResourceData) (sql.EditAlert, error) { common.DataToStructPointer(data, s, a) - return sql.EditAlert{ + ea := sql.EditAlert{ AlertId: data.Id(), Name: a.Name, Options: sql.AlertOptions{ @@ -67,7 +72,13 @@ func (a *AlertEntity) toEditAlertApiObject(s map[string]*schema.Schema, data *sc }, QueryId: a.QueryId, Rearm: a.Rearm, - }, nil + } + + var err error + if a.Options.EmptyResultState != "" { + err = ea.Options.EmptyResultState.Set(a.Options.EmptyResultState) + } + return ea, err } func (a *AlertEntity) fromAPIObject(apiAlert *sql.Alert, s map[string]*schema.Schema, data *schema.ResourceData) error { @@ -89,6 +100,7 @@ func (a *AlertEntity) fromAPIObject(apiAlert *sql.Alert, s map[string]*schema.Sc Muted: apiAlert.Options.Muted, CustomBody: apiAlert.Options.CustomBody, CustomSubject: apiAlert.Options.CustomSubject, + EmptyResultState: apiAlert.Options.EmptyResultState.String(), } // value can be a string or a float64 - unfortunately this can't be encoded in OpenAPI yet