Hello,
I basically have a service using a child New Relic alerting module, say located in the modules/terraform-nr-alert
folder, which has it’s say 2 alert conditions (newrelic_nrql_alert_condition
s resources) and two respective associated polices (newrelic_alert_policy
resources). Within the each of the two newrelic_alert_policy
s, they are already tied to a required newrelic_alert_channel.email_channel.id
in the channel_ids
property of each of the two newrelic_alert_policy
s.
I want to now create a potentially optional teams notification child module - on the same level as the modules/terraform-nr-alert
module of course - calling it say modules/terraform-nr-teams-notifications
, and using a webhook URL for MSFT teams inside a newrelic_alert_channel
resource. Optional as in, make a reference in the modules/terraform-nr-alert
in each of the two newrelic_alert_policy
resources in their channel_ids
property, to that teams webhook notification channel.
So say in the modules/terraform-nr-alert
folder I have one of the already existing alert policies below,
resource "newrelic_alert_policy" "policy__app" {
name = "Web App"
incident_preference = "PER_CONDITION_AND_TARGET"
channel_ids = [ newrelic_alert_channel.email_channel.id ]
}
Could I make an optional reference in channel_ids
property above to the modules/terraform-nr-teams-notifications
newrelic_alert_channel
resource containing the teams webhook (let’s call it say "teams_channel"
)?
I know I could make it non-optional and put it in like so, if I called the modules/terraform-nr-teams-notifications
module say "nr_teams_notifications"
, and called the newrelic_alert_channel
in that say "teams_channel"
,
resource "newrelic_alert_policy" "policy__app" {
name = "Web App"
incident_preference = "PER_CONDITION_AND_TARGET"
channel_ids = [ newrelic_alert_channel.email_channel.id,
module.nr_teams_notifications.newrelic_alert_channel.teams_channel.id ]
}
I think.
But how to make that module.nr_teams_notifications.newrelic_alert_channel.teams_channel.id
above optional in case someone does not want to use my modules/terraform-nr-teams-notifications
child module, but only the modules/terraform-nr-alert
with its already required email channel alone?
Perhaps I could also not make a separate teams module and still just use the existing modules/terraform-nr-alert
, and make the root/parent module pass in the webhook url in a variable that is made optional/conditional somehow, and based on whether that is provided or not the modules/terraform-nr-alert
can create the alert channel for the msft teams webhook.
Seems like I might be able to do exactly right above depending on whether a variable for the webhook url is passed in a variable to the modules/terraform-nr-alert
module, by doing something similar to the below:
I guess the question is, if the above is the way to go, how do I make that inclusion in the resource "newrelic_alert_policy" "policy__app" { .. }
above optional in its channel_ids
property shown above? Could I just perhaps do something like an expression by tacking on || null
like in the below(again, just still using this inside the existing modules/terraform-nr-alert
module) ?
resource "newrelic_alert_policy" "policy__app" {
name = "Web App"
incident_preference = "PER_CONDITION_AND_TARGET"
channel_ids = [ newrelic_alert_channel.email_channel.id,
newrelic_alert_channel.teams_channel.id || null ]
}
Or perhaps, better yet, just define the variables with a default
of ""
- or would I do null
?:
variable "teams_channel" {
type = string
default = ""
}
and keep the above attribute assignment without the || null
- if that even worked - and this instead
resource "newrelic_alert_policy" "policy__app" {
name = "Web App"
incident_preference = "PER_CONDITION_AND_TARGET"
channel_ids = [ newrelic_alert_channel.email_channel.id,
newrelic_alert_channel.teams_channel.id ]
}