Nick Clark
Nick Clark

Reputation: 21

Need to have separate notification channels per environment

I am trying to write a single google_monitoring_alert_policy resource for both prod and dev and I seem to be having an issue with having separate notification channels per environment.

This is what I have now:

resource "google_monitoring_notification_channel" "pagerduty" {
  #Only use pagerduty in prod
  count        = "${var.environment == "production" ? 1 : 0}"
  display_name = "Pagerduty Alerting"

  type = "pagerduty"

  labels = {
    service_key = "${var.pagerduty_service_key}"
  }
}
resource "google_monitoring_alert_policy" "noisy_zk" {
...
  notification_channels = [
    "${split(" ", var.environment == "production" ? "${google_monitoring_notification_channel.pagerduty.name} ${google_monitoring_notification_channel.slack.name}" : "${google_monitoring_notification_channel.slack.name}")}",
  ]

Basically what I'm trying to achieve is that I only want to create and use the pagerduty resource in production envs. The error Im getting is this:

Error: Error running plan: 1 error occurred:
    * module.stackdriver.google_monitoring_alert_policy.noisy_zk: 1 error occurred:
    * module.stackdriver.google_monitoring_alert_policy.noisy_zk: Resource 'google_monitoring_notification_channel.pagerduty' not found for variable 'google_monitoring_notification_channel.pagerduty.name'

Which seems to indicate TF wants to render out all variables even if they're not in use. Any ideas welcome!

Upvotes: 1

Views: 640

Answers (1)

Nick Clark
Nick Clark

Reputation: 21

This wasn't exactly solved since this is due to a bug in versions <0.12. So I've just created the resource and will remove it once we upgrade.

Upvotes: 1

Related Questions