diff --git a/_dynatrace-base-modules/dynatrace-alerting-profile/_interface.tf b/_dynatrace-base-modules/dynatrace-alerting-profile/_interface.tf index 0e15354..e95cc57 100644 --- a/_dynatrace-base-modules/dynatrace-alerting-profile/_interface.tf +++ b/_dynatrace-base-modules/dynatrace-alerting-profile/_interface.tf @@ -1,7 +1,7 @@ ## --- variables # AlertingProfiles Variables -variable mzId {default = ""} +variable mzId {default = ""} variable alertingProfileName {default = ""} variable delay_AVAILABILITY {default = 0} variable delay_CUSTOM_ALERT {default = 0} @@ -9,3 +9,5 @@ variable delay_ERROR {default = 0} variable delay_MONITORING_UNAVAILABLE {default = 0} variable delay_PERFORMANCE {default = 0} variable delay_RESOURCE_CONTENTION {default = 0} +variable tag_filters {} +variable include_mode {default = "NONE"} diff --git a/_dynatrace-base-modules/dynatrace-alerting-profile/dynatrace-alerting-profile.tf b/_dynatrace-base-modules/dynatrace-alerting-profile/dynatrace-alerting-profile.tf index ba4015d..ba5b2e1 100644 --- a/_dynatrace-base-modules/dynatrace-alerting-profile/dynatrace-alerting-profile.tf +++ b/_dynatrace-base-modules/dynatrace-alerting-profile/dynatrace-alerting-profile.tf @@ -15,7 +15,15 @@ resource dynatrace_alerting_profile main { delay_in_minutes = "${var.delay_AVAILABILITY}" severity_level = "AVAILABILITY" tag_filter { - include_mode = "NONE" + include_mode = "${var.include_mode}" + dynamic "tag_filters" { + for_each = var.include_mode != "NONE" ? var.tag_filters : [] + content { + context = tag_filters.value["context"] + key = tag_filters.value["key"] + value = tag_filters.value["value"] + } + } } } @@ -23,7 +31,15 @@ resource dynatrace_alerting_profile main { delay_in_minutes = "${var.delay_CUSTOM_ALERT}" severity_level = "CUSTOM_ALERT" tag_filter { - include_mode = "NONE" + include_mode = "${var.include_mode}" + dynamic "tag_filters" { + for_each = var.include_mode != "NONE" ? var.tag_filters : [] + content { + context = tag_filters.value["context"] + key = tag_filters.value["key"] + value = tag_filters.value["value"] + } + } } } @@ -31,7 +47,15 @@ resource dynatrace_alerting_profile main { delay_in_minutes = "${var.delay_ERROR}" severity_level = "ERROR" tag_filter { - include_mode = "NONE" + include_mode = "${var.include_mode}" + dynamic "tag_filters" { + for_each = var.include_mode != "NONE" ? var.tag_filters : [] + content { + context = tag_filters.value["context"] + key = tag_filters.value["key"] + value = tag_filters.value["value"] + } + } } } @@ -39,14 +63,30 @@ resource dynatrace_alerting_profile main { delay_in_minutes = "${var.delay_MONITORING_UNAVAILABLE}" severity_level = "MONITORING_UNAVAILABLE" tag_filter { - include_mode = "NONE" + include_mode = "${var.include_mode}" + dynamic "tag_filters" { + for_each = var.include_mode != "NONE" ? var.tag_filters : [] + content { + context = tag_filters.value["context"] + key = tag_filters.value["key"] + value = tag_filters.value["value"] + } + } } } rules { delay_in_minutes = "${var.delay_PERFORMANCE}" severity_level = "PERFORMANCE" tag_filter { - include_mode = "NONE" + include_mode = "${var.include_mode}" + dynamic "tag_filters" { + for_each = var.include_mode != "NONE" ? var.tag_filters : [] + content { + context = tag_filters.value["context"] + key = tag_filters.value["key"] + value = tag_filters.value["value"] + } + } } } @@ -54,7 +94,15 @@ resource dynatrace_alerting_profile main { delay_in_minutes = "${var.delay_RESOURCE_CONTENTION}" severity_level = "RESOURCE_CONTENTION" tag_filter { - include_mode = "NONE" + include_mode = "${var.include_mode}" + dynamic "tag_filters" { + for_each = var.include_mode != "NONE" ? var.tag_filters : [] + content { + context = tag_filters.value["context"] + key = tag_filters.value["key"] + value = tag_filters.value["value"] + } + } } } diff --git a/eupreprod/CD_ABC/alerting-profile.tf b/eupreprod/CD_ABC/alerting-profile.tf index 596ca12..f33cf87 100644 --- a/eupreprod/CD_ABC/alerting-profile.tf +++ b/eupreprod/CD_ABC/alerting-profile.tf @@ -3,7 +3,6 @@ module ap1 { source = "../../_dynatrace-base-modules/dynatrace-alerting-profile" mzId = module.mz1.id - #mzId = "12323" alertingProfileName = "Test123" delay_AVAILABILITY = 0 delay_CUSTOM_ALERT = 10 @@ -11,6 +10,19 @@ module ap1 { delay_MONITORING_UNAVAILABLE = 20 delay_PERFORMANCE = 10 delay_RESOURCE_CONTENTION = 0 - + + #Tag Filters + include_mode = "INCLUDE_ALL" + tag_filters = [{ + context = "CONTEXTLESS" + key = "Environment" + value = "PROD" + }, + { + context = "CONTEXTLESS" + key = "ms-id" + value = "ABC" + } + ] } \ No newline at end of file