Skip to content

Commit

Permalink
replace var with value, add missing values to variables
Browse files Browse the repository at this point in the history
  • Loading branch information
DFurt committed Dec 12, 2024
1 parent 5f2c6f9 commit 1547372
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 90 deletions.
62 changes: 31 additions & 31 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ locals {
all_monitor_resources = merge(newrelic_synthetics_monitor.simple, newrelic_synthetics_script_monitor.script, newrelic_synthetics_step_monitor.step, newrelic_synthetics_broken_links_monitor.broken_links, newrelic_synthetics_cert_check_monitor.cert_check)

# constructs the name string for each monitor in a single location to avoid repetition.
prefix_suffix_map = {for key, _ in local.all_monitors: key => "${local.nr_entity_prefix}${key}${local.nr_entity_suffix}"}
prefix_suffix_map = { for key, _ in local.all_monitors : key => "${local.nr_entity_prefix}${key}${local.nr_entity_suffix}" }

}

data "newrelic_entity" "this" {
for_each = {for key, value in local.all_monitors: key => value if var.create_non_critical_apm_resources || var.create_critical_apm_resources}
for_each = { for key, value in local.all_monitors : key => value if value.create_non_critical_apm_resources || value.create_critical_apm_resources }

name = local.prefix_suffix_map[each.key]
domain = "APM"
type = "APPLICATION"
}

data "newrelic_entity" "browser_application" {
for_each = {for key, value in var.browser_monitors: key => value if var.create_non_critical_browser_alert || var.create_critical_browser_alert}
for_each = { for key, value in var.browser_monitors : key => value if value.create_non_critical_browser_alert || value.create_critical_browser_alert }

name = local.prefix_suffix_map[each.key]
domain = "BROWSER"
Expand Down Expand Up @@ -371,22 +371,22 @@ resource "pagerduty_service_integration" "synthetics_newrelic" {
##########################

resource "newrelic_alert_policy" "critical_apm_response_time" {
for_each = {for key, value in local.all_monitors: key => value if var.create_critical_apm_resources}
for_each = { for key, value in local.all_monitors : key => value if value.create_critical_apm_resources }

name = "APM-${local.prefix_suffix_map[each.key]}-response-time-Critical"
incident_preference = "PER_CONDITION_AND_TARGET"
}

resource "newrelic_alert_policy" "critical_apm_error_rate" {
for_each = {for key, value in local.all_monitors: key => value if var.create_critical_apm_resources}
for_each = { for key, value in local.all_monitors : key => value if value.create_critical_apm_resources }

name = "APM-${local.prefix_suffix_map[each.key]}-error-rate-Critical"
incident_preference = "PER_CONDITION_AND_TARGET"
}

resource "newrelic_notification_destination" "critical_apm" {
# we create only one
count = length({for key, value in local.all_monitors: key => value if var.create_critical_apm_resources}) > 0 ? 1 : 0
count = length({ for key, value in local.all_monitors : key => value if value.create_critical_apm_resources }) > 0 ? 1 : 0

name = "${pagerduty_service.critical["NewRelic"].name}-APM"
type = "PAGERDUTY_SERVICE_INTEGRATION"
Expand All @@ -402,7 +402,7 @@ resource "newrelic_notification_destination" "critical_apm" {
}

resource "newrelic_notification_channel" "critical_apm_response_time" {
for_each = {for key, value in local.all_monitors: key => value if var.create_critical_apm_resources}
for_each = { for key, value in local.all_monitors : key => value if value.create_critical_apm_resources }

name = "APM-${local.prefix_suffix_map[each.key]}-response-time-Critical"
type = "PAGERDUTY_SERVICE_INTEGRATION"
Expand All @@ -424,7 +424,7 @@ resource "newrelic_notification_channel" "critical_apm_response_time" {
}

resource "newrelic_notification_channel" "critical_apm_error_rate" {
for_each = {for key, value in local.all_monitors: key => value if var.create_critical_apm_resources}
for_each = { for key, value in local.all_monitors : key => value if value.create_critical_apm_resources }

name = "APM-${local.prefix_suffix_map[each.key]}-error-rate-Critical"
type = "PAGERDUTY_SERVICE_INTEGRATION"
Expand All @@ -446,7 +446,7 @@ resource "newrelic_notification_channel" "critical_apm_error_rate" {
}

resource "newrelic_nrql_alert_condition" "critical_response_time" {
for_each = {for key, value in local.all_monitors: key => value if var.create_critical_apm_resources}
for_each = { for key, value in local.all_monitors : key => value if value.create_critical_apm_resources }

policy_id = newrelic_alert_policy.critical_apm_response_time[each.key].id
name = "${data.newrelic_entity.this[each.key].name}-Critical-response-time"
Expand All @@ -465,7 +465,7 @@ resource "newrelic_nrql_alert_condition" "critical_response_time" {
}

resource "newrelic_nrql_alert_condition" "critical_error_rate" {
for_each = {for key, value in local.all_monitors: key => value if var.create_critical_apm_resources}
for_each = { for key, value in local.all_monitors : key => value if value.create_critical_apm_resources }

policy_id = newrelic_alert_policy.critical_apm_error_rate[each.key].id
name = "${data.newrelic_entity.this[each.key].name}-Critical-error-rate"
Expand All @@ -484,7 +484,7 @@ resource "newrelic_nrql_alert_condition" "critical_error_rate" {
}

resource "newrelic_workflow" "critical_apm_response_time" {
for_each = {for key, value in local.all_monitors: key => value if var.create_critical_apm_resources}
for_each = { for key, value in local.all_monitors : key => value if value.create_critical_apm_resources }

name = "APM-${data.newrelic_entity.this[each.key].name}-Critical-response-time"
muting_rules_handling = "NOTIFY_ALL_ISSUES"
Expand All @@ -506,7 +506,7 @@ resource "newrelic_workflow" "critical_apm_response_time" {
}

resource "newrelic_workflow" "critical_apm_error_rate" {
for_each = {for key, value in local.all_monitors: key => value if var.create_critical_apm_resources}
for_each = { for key, value in local.all_monitors : key => value if value.create_critical_apm_resources }

name = "APM-${data.newrelic_entity.this[each.key].name}-Critical-error-rate"
muting_rules_handling = "NOTIFY_ALL_ISSUES"
Expand Down Expand Up @@ -535,7 +535,7 @@ resource "newrelic_workflow" "critical_apm_error_rate" {


resource "newrelic_notification_destination" "non_critical_apm" {
count = length({for key, value in local.all_monitors: key => value if var.create_non_critical_apm_resources}) > 0 ? 1 : 0
count = length({ for key, value in local.all_monitors : key => value if value.create_non_critical_apm_resources }) > 0 ? 1 : 0

name = "${pagerduty_service.non_critical["NewRelic"].name}-APM"
type = "PAGERDUTY_SERVICE_INTEGRATION"
Expand All @@ -551,21 +551,21 @@ resource "newrelic_notification_destination" "non_critical_apm" {
}

resource "newrelic_alert_policy" "non_critical_apm_response_time" {
for_each = {for key, value in local.all_monitors: key => value if var.create_non_critical_apm_resources}
for_each = { for key, value in local.all_monitors : key => value if value.create_non_critical_apm_resources }

name = "APM-${local.prefix_suffix_map[each.key]}-response-time-Non_Critical"
incident_preference = "PER_CONDITION_AND_TARGET"
}

resource "newrelic_alert_policy" "non_critical_apm_error_rate" {
for_each = {for key, value in local.all_monitors: key => value if var.create_non_critical_apm_resources}
for_each = { for key, value in local.all_monitors : key => value if value.create_non_critical_apm_resources }

name = "APM-${local.prefix_suffix_map[each.key]}-error-rate-Non_Critical"
incident_preference = "PER_CONDITION_AND_TARGET"
}

resource "newrelic_notification_channel" "non_critical_apm_response_time" {
for_each = {for key, value in local.all_monitors: key => value if var.create_non_critical_apm_resources}
for_each = { for key, value in local.all_monitors : key => value if value.create_non_critical_apm_resources }

name = "APM-${local.prefix_suffix_map[each.key]}-response-time-Non_Critical"
type = "PAGERDUTY_SERVICE_INTEGRATION"
Expand All @@ -588,7 +588,7 @@ resource "newrelic_notification_channel" "non_critical_apm_response_time" {
}

resource "newrelic_notification_channel" "non_critical_apm_error_rate" {
for_each = {for key, value in local.all_monitors: key => value if var.create_non_critical_apm_resources}
for_each = { for key, value in local.all_monitors : key => value if value.create_non_critical_apm_resources }

name = "APM-${local.prefix_suffix_map[each.key]}-error-rate-Non_Critical"
type = "PAGERDUTY_SERVICE_INTEGRATION"
Expand All @@ -609,7 +609,7 @@ resource "newrelic_notification_channel" "non_critical_apm_error_rate" {
}

resource "newrelic_nrql_alert_condition" "non_critical_response_time" {
for_each = {for key, value in local.all_monitors: key => value if var.create_non_critical_apm_resources}
for_each = { for key, value in local.all_monitors : key => value if value.create_non_critical_apm_resources }

policy_id = newrelic_alert_policy.non_critical_apm_response_time[each.key].id
name = "${data.newrelic_entity.this[each.key].name}-Non_Critical-response-time"
Expand All @@ -628,7 +628,7 @@ resource "newrelic_nrql_alert_condition" "non_critical_response_time" {
}

resource "newrelic_nrql_alert_condition" "non_critical_error_rate" {
for_each = {for key, value in local.all_monitors: key => value if var.create_non_critical_apm_resources}
for_each = { for key, value in local.all_monitors : key => value if value.create_non_critical_apm_resources }

policy_id = newrelic_alert_policy.non_critical_apm_error_rate[each.key].id
name = "${data.newrelic_entity.this[each.key].name}-Non_Critical-error-rate"
Expand All @@ -647,7 +647,7 @@ resource "newrelic_nrql_alert_condition" "non_critical_error_rate" {
}

resource "newrelic_workflow" "non_critical_apm_response_time" {
for_each = {for key, value in local.all_monitors: key => value if var.create_non_critical_apm_resources}
for_each = { for key, value in local.all_monitors : key => value if value.create_non_critical_apm_resources }

name = "APM-${data.newrelic_entity.this[each.key].name}-Non_Critical-response-time"
muting_rules_handling = "NOTIFY_ALL_ISSUES"
Expand All @@ -669,7 +669,7 @@ resource "newrelic_workflow" "non_critical_apm_response_time" {
}

resource "newrelic_workflow" "non_critical_apm_error_rate" {
for_each = {for key, value in local.all_monitors: key => value if var.create_non_critical_apm_resources}
for_each = { for key, value in local.all_monitors : key => value if value.create_non_critical_apm_resources }

name = "APM-${data.newrelic_entity.this[each.key].name}-Non_Critical-error-rate"
muting_rules_handling = "NOTIFY_ALL_ISSUES"
Expand Down Expand Up @@ -697,7 +697,7 @@ resource "newrelic_workflow" "non_critical_apm_error_rate" {
##########################

resource "newrelic_notification_destination" "non_critical_browser" {
count = length({for key, value in var.browser_monitors: key => value if var.create_non_critical_browser_alert}) > 0 ? 1 : 0
count = length({ for key, value in var.browser_monitors : key => value if value.create_non_critical_browser_alert }) > 0 ? 1 : 0

name = "${pagerduty_service.non_critical["NewRelic"].name}-Browser"
type = "PAGERDUTY_SERVICE_INTEGRATION"
Expand All @@ -713,14 +713,14 @@ resource "newrelic_notification_destination" "non_critical_browser" {
}

resource "newrelic_alert_policy" "non_critical_browser_pageload" {
for_each = {for key, value in var.browser_monitors: key => value if var.create_non_critical_browser_alert}
for_each = { for key, value in var.browser_monitors : key => value if value.create_non_critical_browser_alert }

name = "Browser-${local.prefix_suffix_map[each.key]}-Non-Critical-Pageload"
incident_preference = "PER_CONDITION_AND_TARGET"
}

resource "newrelic_notification_channel" "non_critical_browser_pageload" {
for_each = {for key, value in var.browser_monitors: key => value if var.create_non_critical_browser_alert}
for_each = { for key, value in var.browser_monitors : key => value if value.create_non_critical_browser_alert }

name = "Browser-${local.prefix_suffix_map[each.key]}-Non-Critical-Pageload"
type = "PAGERDUTY_SERVICE_INTEGRATION"
Expand All @@ -741,7 +741,7 @@ resource "newrelic_notification_channel" "non_critical_browser_pageload" {
}

resource "newrelic_nrql_alert_condition" "non_critical_browser_pageload" {
for_each = {for key, value in var.browser_monitors: key => value if var.create_non_critical_browser_alert}
for_each = { for key, value in var.browser_monitors : key => value if value.create_non_critical_browser_alert }

policy_id = newrelic_alert_policy.non_critical_browser_pageload[each.key].id
name = "${data.newrelic_entity.browser_application[each.key].name}-Non-Critical-Browser-Pageload"
Expand All @@ -760,7 +760,7 @@ resource "newrelic_nrql_alert_condition" "non_critical_browser_pageload" {
}

resource "newrelic_workflow" "non_critical_browser_pageload" {
for_each = {for key, value in var.browser_monitors: key => value if var.create_non_critical_browser_alert}
for_each = { for key, value in var.browser_monitors : key => value if value.create_non_critical_browser_alert }

name = "${data.newrelic_entity.browser_application[each.key].name}-Non-Critical-Browser-Pageload"
muting_rules_handling = "NOTIFY_ALL_ISSUES"
Expand Down Expand Up @@ -788,7 +788,7 @@ resource "newrelic_workflow" "non_critical_browser_pageload" {
##########################

resource "newrelic_notification_destination" "critical_browser" {
count = length({for key, value in var.browser_monitors: key => value if var.create_critical_browser_alert}) > 0 ? 1 : 0
count = length({ for key, value in var.browser_monitors : key => value if value.create_critical_browser_alert }) > 0 ? 1 : 0

name = "${pagerduty_service.critical["NewRelic"].name}-Browser"
type = "PAGERDUTY_SERVICE_INTEGRATION"
Expand All @@ -804,14 +804,14 @@ resource "newrelic_notification_destination" "critical_browser" {
}

resource "newrelic_alert_policy" "critical_browser_pageload" {
for_each = {for key, value in var.browser_monitors: key => value if var.create_critical_browser_alert}
for_each = { for key, value in var.browser_monitors : key => value if value.create_critical_browser_alert }

name = "Browser-${local.prefix_suffix_map[each.key]}-Critical-Pageload"
incident_preference = "PER_CONDITION_AND_TARGET"
}

resource "newrelic_notification_channel" "critical_browser_pageload" {
for_each = {for key, value in var.browser_monitors: key => value if var.create_critical_browser_alert}
for_each = { for key, value in var.browser_monitors : key => value if value.create_critical_browser_alert }

name = "Browser-${local.prefix_suffix_map[each.key]}-Critical-Pageload"
type = "PAGERDUTY_SERVICE_INTEGRATION"
Expand All @@ -832,7 +832,7 @@ resource "newrelic_notification_channel" "critical_browser_pageload" {
}

resource "newrelic_nrql_alert_condition" "critical_browser_pageload" {
for_each = {for key, value in var.browser_monitors: key => value if var.create_critical_browser_alert}
for_each = { for key, value in var.browser_monitors : key => value if value.create_critical_browser_alert }

policy_id = newrelic_alert_policy.critical_browser_pageload[each.key].id
name = "${data.newrelic_entity.browser_application[each.key].name}-Critical-Browser-Pageload"
Expand All @@ -851,7 +851,7 @@ resource "newrelic_nrql_alert_condition" "critical_browser_pageload" {
}

resource "newrelic_workflow" "critical_browser_pageload" {
for_each = {for key, value in var.browser_monitors: key => value if var.create_critical_browser_alert}
for_each = { for key, value in var.browser_monitors : key => value if value.create_critical_browser_alert }

name = "${data.newrelic_entity.browser_application[each.key].name}-Critical-Browser-Pageload"
muting_rules_handling = "NOTIFY_ALL_ISSUES"
Expand Down
Loading

0 comments on commit 1547372

Please sign in to comment.