Skip to content

Commit 35fd3fd

Browse files
committed
added examples for alarm
Signed-off-by: Karthic Ravindran <[email protected]>
1 parent 2f4b436 commit 35fd3fd

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

examples/alarm/main.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module "alarm" {
2+
source = "./modules/alarm"
3+
alarm_def = local.alarm_def
4+
compartment_ocid = local.compartment_ocid
5+
notification = local.notification
6+
7+
}
8+
9+
locals {
10+
compartment_ocid = "<compartment id where notification and alarm will be created>"
11+
notification = {
12+
demotopic = {
13+
subscription = {
14+
sub1 = {
15+
protocol = "EMAIL"
16+
endpoint = "<email address>"
17+
}
18+
}
19+
freeform_tags = {
20+
env = "test"
21+
}
22+
}
23+
}
24+
alarm_def = {
25+
"testdelete" = {
26+
destination = "demotopic"
27+
namespace = "oci_computeagent"
28+
query = "CpuUtilization[1m].mean() > 70"
29+
}
30+
}
31+
}

examples/alarm/provider.tf.example

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
provider "oci" {
2+
region = "<region where alarm,notification to be created>"
3+
fingerprint = ""
4+
private_key_path = ""
5+
6+
tenancy_ocid = ""
7+
user_ocid = ""
8+
9+
}
10+
11+
terraform {
12+
required_providers {
13+
oci = {
14+
source = "oracle/oci"
15+
version = ">= 4.67.3"
16+
}
17+
}
18+
required_version = ">= 1.3.0"
19+
}

modules/alarm/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ resource "oci_ons_subscription" "this" {
3636
resource "oci_monitoring_alarm" "this" {
3737
for_each = length(var.alarm_def) > 0 ? var.alarm_def : {}
3838
compartment_id = var.compartment_ocid
39-
destinations = [try(oci_ons_notification_topic.this_topic[each.value.destination].id, data.oci_ons_notification_topics.existing_topic[each.value.destination].notification_topics[0].topic_id, each.value.destination)]
39+
destinations = [try(oci_ons_notification_topic.this[each.value.destination].id, data.oci_ons_notification_topics.existing_topic[each.value.destination].notification_topics[0].topic_id, each.value.destination)]
4040
display_name = var.label_prefix == "none" ? each.key : format("%s_%s", var.label_prefix, each.key)
4141
is_enabled = each.value.is_enabled
4242
metric_compartment_id = each.value.metric_compartment_id == null ? var.compartment_ocid : each.value.metric_compartment
@@ -64,7 +64,7 @@ locals {
6464
notification_subscription = flatten([
6565
for topic_key, topic_value in var.notification : [
6666
for subscription_key, subscription_value in topic_value.subscription : {
67-
topic_id = topic_value.create_topic ? oci_ons_notification_topic.this_topic[topic_key].id : data.oci_ons_notification_topics.existing_topic[topic_key].notification_topics[0].topic_id
67+
topic_id = topic_value.create_topic ? oci_ons_notification_topic.this[topic_key].id : data.oci_ons_notification_topics.existing_topic[topic_key].notification_topics[0].topic_id
6868
protocol = subscription_value.protocol
6969
endpoint = subscription_value.endpoint
7070
subscription = format("%s_%s", topic_key, subscription_key)

modules/alarm/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
output "topic_ids" {
55
description = "Notification Topic OCID"
6-
value = { for k in oci_ons_notification_topic.this_topic : k.name => k.topic_id }
6+
value = { for k in oci_ons_notification_topic.this : k.name => k.topic_id }
77
}

0 commit comments

Comments
 (0)