diff --git a/modules/monitoring-tools/main.tftest.hcl b/modules/monitoring-tools/main.tftest.hcl index a3c80d6..10b2de7 100644 --- a/modules/monitoring-tools/main.tftest.hcl +++ b/modules/monitoring-tools/main.tftest.hcl @@ -111,6 +111,42 @@ run "valid_no_filter" { } } +run "invalid_label" { + module { + source = "./" + } + + variables { + project_id = "project_id" + + target = { + title = "Title" + metric = "xxx.googleapis.com/xxx/xxx" + resource_type = "xxx" + label = "resource.xxx" + name = "xxx" + filter = "AND xxx = xxx" + reducer = "REDUCE_NONE" + aligner = "ALIGN_DELTA" + alert = { + "warn" = { + channel = "#warn" + window = "300s" + value = 0.65 + } + } + } + + secrets = "auth_token: xoxb-xxx" + } + + command = plan + + expect_failures = [ + var.target.label, + ] +} + run "invalid_filter" { module { source = "./" @@ -147,7 +183,7 @@ run "invalid_filter" { ] } -run "invalid_label" { +run "invalid_channel" { module { source = "./" } @@ -159,16 +195,21 @@ run "invalid_label" { title = "Title" metric = "xxx.googleapis.com/xxx/xxx" resource_type = "xxx" - label = "resource.xxx" + label = "resource.labels.xxx" name = "xxx" filter = "AND xxx = xxx" reducer = "REDUCE_NONE" aligner = "ALIGN_DELTA" alert = { "error" = { - channel = "#warn" + channel = "error" window = "300s" - value = 0.65 + value = 0.95 + } + "warn" = { + channel = "warn" + window = "300s" + value = 0.8 } } } @@ -179,6 +220,7 @@ run "invalid_label" { command = plan expect_failures = [ - var.target.label, + var.target.alert["error"].channel, + var.target.alert["warn"].channel, ] } diff --git a/modules/monitoring-tools/variables.tf b/modules/monitoring-tools/variables.tf index 8cb3d5b..9c8b658 100644 --- a/modules/monitoring-tools/variables.tf +++ b/modules/monitoring-tools/variables.tf @@ -35,6 +35,10 @@ variable "target" { condition = var.target.filter == "" ? true : startswith(var.target.filter, "AND ") error_message = "`var.target.filter` must start with `AND `." } + validation { + condition = alltrue([for alert in var.target.alert : startswith(alert.channel, "#")]) + error_message = "`var.target.alert['*'].channel` must start with `#`." + } } variable "secrets" {