Terraform Snowflake Module to Manage Snowflake Alerts
This is a repository that makes a snowflake alert:
- snowflake_alert
Example CICD with BitBucket
and Codefresh
:
In this code, the entire alert_schedule
block is optional, using the dynamic
block this module creates a variable that indicates whether the alert_schedule
block which should be included or not via the include_alert_schedule
variable.
variable "include_alert_schedule" {
description = "Whether to include the alert_schedule block"
type = bool
default = false
}
In this code, var.include_alert_schedule ? [1] : []
is a conditional expression. If var.include_alert_schedule
is true, the dynamic alert_schedule
block will be created. The default is false, and the dynamic alert_schedule
block will not be created!
Please note that if var.include_alert_schedule
is true:
- You should ensure at least one of
var.alert_interval
andvar.cron_expression
is not null in your variable definitions or in the code where you are calling this module. - If you use
var.cron_expression
, you should specify this as a cron string, default is set toUTC
and you can overwrite it by specifying thetime_zone
variable.
To use the module you will need to use something adhering to the following format:
module "snowflake_alert_bi_data_freshness_alert" {
source = "https://github.com/Richard-Barrett/terraform-snowflake-alerts"
version = "0.0.1"
database = "BI"
name = "BI_DATA_FRESHNESS_ALERT"
schema = "BI"
warehouse = "BI"
condition_sql = "select 1 as c"
action_sql = "select 1 as c"
}
What if you want to specify the condition_sql
and action_sql
as a file?
module "snowflake_alert_bi_data_freshness_alert" {
source = "https://github.com/Richard-Barrett/terraform-snowflake-alerts"
version = "0.0.1"
database = "BI"
name = "BI_DATA_FRESHNESS_ALERT"
schema = "BI"
warehouse = "BI"
condition_sql = file("${path.module}/${var.condition_sql_file}")
action_sql = file("${path.module}/${var.action_sql_file}")
}
In this code, ${path.module}/${var.condition_sql_file}
and ${path.module}/${var.action_sql_file}
are the paths to the SQL files relative to the module. The file
function reads the content of the files and assigns it to the condition
and action
attributes.
Please replace "condition.sql"
and "action.sql"
with the names of your SQL files. If the files are in a subdirectory of the module, you need to include the subdirectory in the file name, like "subdirectory/condition.sql"
.
In general you may want to use the module in the following way:
module "snowflake_alert_bi_data_freshness_alert" {
source = "https://github.com/Richard-Barrett/terraform-snowflake-alerts"
version = "0.0.1"
database = "BI"
schema = "BI"
name = "BI_DATA_FRESHNESS_ALERT"
warehouse = "BI"
condition_sql = file("${path.module}/conditions/condition.sql")
action_sql = file("${path.module}/actions/action.sql")
}
This means that where ever you are calling the alert module you will have a directory for both conditions
and actions
thereby allowing you to control and organize the way you call alerts
├───actions
└───conditions
main.tf
variables.tf
providers.tf
outputs.tf
data.tf
In overview, this repository acts as a digestible module that allows you to create an alert in Snowflake in a modular way.
Name | Version |
---|---|
terraform | >= 1.5.6 |
snowflake | ~> 0.89.0 |
Name | Version |
---|---|
snowflake | ~> 0.89.0 |
No modules.
Name | Type |
---|---|
snowflake_alert.alert | resource |
Name | Description | Type | Default | Required |
---|---|---|---|---|
action_sql | SQL action to take when the alert is triggere. | string |
n/a | yes |
alert_interval | value in minutes for the alert interval. | number |
10 |
no |
comment | Comment for the alert or added description of alert | string |
"" |
no |
condition_sql | SQL condition to trigger the alert. | string |
n/a | yes |
cron_expression | The cron expression for the alert schedule | string |
null |
no |
database | Name of the Database you want to alert on. | string |
n/a | yes |
enabled | (Boolean) Specifies if an alert should be 'started' (enabled) after creation or should remain 'suspended' (default). | bool |
true |
no |
include_alert_schedule | Whether to include the alert_schedule block | bool |
true |
no |
name | Name of the alert | string |
n/a | yes |
schema | Name of the Schema you want to alert on. | string |
n/a | yes |
time_zone | The timezone for the cron schedule | string |
"UTC" |
no |
warehouse | Name of the Warehouse you want to alert on | string |
n/a | yes |
No outputs.