Skip to content

Commit 5f01aad

Browse files
authored
Merge pull request #1 from karthicgit/main
Initial commit
2 parents 274ef87 + 35fd3fd commit 5f01aad

File tree

17 files changed

+615
-12
lines changed

17 files changed

+615
-12
lines changed

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Local .terraform directories
2+
**/.terraform/*
3+
4+
provider.tf
5+
6+
# .tfstate files
7+
*.tfstate
8+
*.tfstate.*
9+
10+
# .tfvars files
11+
*.tfvars
12+
*.tfvars.json
13+
14+
# Crash log files
15+
crash.log
16+
crash.*.log
17+
18+
# visual code
19+
**/.vscode/*
20+
.DS_Store
21+
22+
.terraform.lock.hcl
23+
24+
# Ignore CLI configuration files
25+
.terraformrc
26+
terraform.rc

README.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
*This repository acts as a template for all of Oracle’s GitHub repositories. It contains information about the guidelines for those repositories. All files and sections contained in this template are mandatory, and a GitHub app ensures alignment with these guidelines. To get started with a new repository, replace the italic paragraphs with the respective text for your project.*
1+
# Oracle Cloud Infrastructure Terraform Module for Observability
22

3-
# Project name
4-
5-
*Describe your project's features, functionality and target audience*
3+
*This module is for creating resources related to Observability in Oracle Cloud Infrastructure*
64

75
## Installation
86

@@ -22,8 +20,6 @@
2220

2321
## Contributing
2422

25-
*If your project has specific contribution requirements, update the CONTRIBUTING.md file to ensure those requirements are clearly explained*
26-
2723
This project welcomes contributions from the community. Before submitting a pull request, please [review our contribution guide](./CONTRIBUTING.md)
2824

2925
## Security
@@ -32,13 +28,7 @@ Please consult the [security guide](./SECURITY.md) for our responsible security
3228

3329
## License
3430

35-
*The correct copyright notice format for both documentation and software is*
36-
"Copyright (c) [year,] year Oracle and/or its affiliates."
37-
*You must include the year the content was first released (on any platform) and the most recent year in which it was revised*
38-
3931
Copyright (c) 2023 Oracle and/or its affiliates.
4032

41-
*Replace this statement if your project is not licensed under the UPL*
42-
4333
Released under the Universal Permissive License v1.0 as shown at
4434
<https://oss.oracle.com/licenses/upl/>.

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+
}

examples/serviceconnector/main.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module "svc" {
2+
source = "./modules/serviceconnector"
3+
service_connector_def = local.service_connector_def
4+
policy_compartment_id = local.policy_compartment_id
5+
dynamic_group = local.dynamic_group
6+
7+
tenancy_ocid = local.tenancy_ocid
8+
providers = {
9+
oci.home = oci.home
10+
}
11+
12+
}
13+
14+
locals {
15+
tenancy_ocid = "<tenancy_ocid>"
16+
dynamic_group = {
17+
dg1 = { compartment_id = "<service connector compartment id>" }
18+
}
19+
policy_compartment_id = "<policy compartment>" #if not set policy will be created default in root compartment
20+
service_connector_def = { sch2 = {
21+
compartment_id = "<service connector compartment id>"
22+
#If policy needs to be created set the below two values. By default its set to false to not create policy
23+
#Set create_policy to true
24+
#set dynamic group name with respect to service connector compartment
25+
create_policy = true
26+
dynamic_group_name = "<dynamicgroupname>"
27+
28+
sch_source = "streaming"
29+
sch_target = "objectstorage"
30+
display_name = "sch2"
31+
32+
stream_id = "existing stream ocid"
33+
target = {
34+
bucket = "<bucket name>"
35+
}
36+
}
37+
}
38+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
provider "oci" {
2+
region = "<region where service connector to be created>"
3+
fingerprint = ""
4+
private_key_path = ""
5+
6+
tenancy_ocid = ""
7+
user_ocid = ""
8+
9+
}
10+
11+
provider "oci" {
12+
alias = "home"
13+
region = "<region>"
14+
fingerprint = ""
15+
private_key_path = ""
16+
17+
tenancy_ocid = ""
18+
user_ocid = ""
19+
20+
}
21+
22+
terraform {
23+
required_providers {
24+
oci = {
25+
source = "oracle/oci"
26+
version = ">= 4.67.3"
27+
}
28+
}
29+
required_version = ">= 1.3.0"
30+
}

modules/alarm/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!-- BEGIN_TF_DOCS -->
2+
## Requirements
3+
4+
| Name | Version |
5+
|------|---------|
6+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
7+
| <a name="requirement_oci"></a> [oci](#requirement\_oci) | >= 4.67.3 |
8+
9+
## Providers
10+
11+
| Name | Version |
12+
|------|---------|
13+
| <a name="provider_oci"></a> [oci](#provider\_oci) | >= 4.67.3 |
14+
15+
## Modules
16+
17+
No modules.
18+
19+
## Resources
20+
21+
| Name | Type |
22+
|------|------|
23+
| [oci_monitoring_alarm.this](https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/monitoring_alarm) | resource |
24+
| [oci_ons_notification_topic.this](https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/ons_notification_topic) | resource |
25+
| [oci_ons_subscription.this](https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/ons_subscription) | resource |
26+
| [oci_ons_notification_topics.existing_topic](https://registry.terraform.io/providers/oracle/oci/latest/docs/data-sources/ons_notification_topics) | data source |
27+
28+
## Inputs
29+
30+
| Name | Description | Type | Default | Required |
31+
|------|-------------|------|---------|:--------:|
32+
| <a name="input_alarm_def"></a> [alarm\_def](#input\_alarm\_def) | OCI Alarm definition | <pre>map(object({<br> destination = string<br> severity = optional(string, "CRITICAL")<br> query = string<br> is_enabled = optional(bool, true)<br> namespace = string<br> metric_compartment_id = optional(string)<br> repeat_notification_duration = optional(string, "PT5M")<br> trigger = optional(string, "PT5M")<br> suppression_from_time = optional(string)<br> suppression_till_time = optional(string)<br> message_format = optional(string, "RAW")<br> body = optional(string, null)<br> freeform_tags = optional(map(string))<br> defined_tags = optional(map(string))<br> }))</pre> | n/a | yes |
33+
| <a name="input_compartment_ocid"></a> [compartment\_ocid](#input\_compartment\_ocid) | Compartment OCID | `string` | n/a | yes |
34+
| <a name="input_label_prefix"></a> [label\_prefix](#input\_label\_prefix) | Prefix to be added to the resources | `string` | `"none"` | no |
35+
| <a name="input_notification"></a> [notification](#input\_notification) | Notification Topic and Subscription | <pre>map(object({<br> description = optional(string)<br> create_topic = optional(bool, true)<br> defined_tags = optional(map(string))<br> freeform_tags = optional(map(string))<br> subscription = map(object({<br> endpoint = string<br> protocol = string<br> }))<br> }))</pre> | n/a | yes |
36+
37+
## Outputs
38+
39+
| Name | Description |
40+
|------|-------------|
41+
| <a name="output_topic_ids"></a> [topic\_ids](#output\_topic\_ids) | Notification Topic OCID |
42+
<!-- END_TF_DOCS -->

modules/alarm/main.tf

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#Copyright (c) 2023 Oracle Corporation and/or its affiliates.
2+
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
3+
4+
resource "oci_ons_notification_topic" "this" {
5+
for_each = { for k, v in var.notification : k => v if v.create_topic == true }
6+
compartment_id = var.compartment_ocid
7+
name = var.label_prefix == "none" ? each.key : format("%s_%s", var.label_prefix, each.key)
8+
9+
description = each.value.description == null ? format("%s%s", each.key, " topic created by Terraform") : each.value.description
10+
defined_tags = each.value.defined_tags
11+
freeform_tags = each.value.freeform_tags
12+
13+
}
14+
15+
data "oci_ons_notification_topics" "existing_topic" {
16+
for_each = { for k, v in var.notification : k => v if v.create_topic == false }
17+
18+
compartment_id = var.compartment_ocid
19+
20+
name = each.key
21+
state = "ACTIVE"
22+
}
23+
24+
resource "oci_ons_subscription" "this" {
25+
for_each = { for v in local.notification_subscription : v.subscription => v }
26+
compartment_id = var.compartment_ocid
27+
endpoint = each.value.endpoint
28+
protocol = each.value.protocol
29+
topic_id = each.value.topic_id
30+
31+
32+
defined_tags = each.value.defined_tags
33+
freeform_tags = each.value.freeform_tags
34+
}
35+
36+
resource "oci_monitoring_alarm" "this" {
37+
for_each = length(var.alarm_def) > 0 ? var.alarm_def : {}
38+
compartment_id = var.compartment_ocid
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)]
40+
display_name = var.label_prefix == "none" ? each.key : format("%s_%s", var.label_prefix, each.key)
41+
is_enabled = each.value.is_enabled
42+
metric_compartment_id = each.value.metric_compartment_id == null ? var.compartment_ocid : each.value.metric_compartment
43+
namespace = each.value.namespace
44+
query = each.value.query
45+
severity = each.value.severity
46+
message_format = each.value.message_format
47+
repeat_notification_duration = each.value.repeat_notification_duration
48+
pending_duration = each.value.trigger
49+
body = each.value.body
50+
defined_tags = each.value.defined_tags
51+
freeform_tags = each.value.freeform_tags
52+
dynamic "suppression" {
53+
for_each = (each.value.suppression_from_time != null && each.value.suppression_till_time != null) ? [1] : []
54+
content {
55+
time_suppress_from = each.value.suppression_from_time
56+
time_suppress_until = each.value.suppression_till_time
57+
}
58+
}
59+
60+
}
61+
62+
63+
locals {
64+
notification_subscription = flatten([
65+
for topic_key, topic_value in var.notification : [
66+
for subscription_key, subscription_value in topic_value.subscription : {
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
68+
protocol = subscription_value.protocol
69+
endpoint = subscription_value.endpoint
70+
subscription = format("%s_%s", topic_key, subscription_key)
71+
defined_tags = topic_value.defined_tags
72+
freeform_tags = topic_value.freeform_tags
73+
}
74+
]
75+
])
76+
}

modules/alarm/outputs.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#Copyright (c) 2023 Oracle Corporation and/or its affiliates.
2+
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
3+
4+
output "topic_ids" {
5+
description = "Notification Topic OCID"
6+
value = { for k in oci_ons_notification_topic.this : k.name => k.topic_id }
7+
}

modules/alarm/variables.tf

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#Copyright (c) 2023 Oracle Corporation and/or its affiliates.
2+
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
3+
4+
variable "compartment_ocid" {
5+
description = "Compartment OCID"
6+
type = string
7+
}
8+
9+
10+
variable "alarm_def" {
11+
description = "OCI Alarm definition"
12+
type = map(object({
13+
destination = string
14+
severity = optional(string, "CRITICAL")
15+
query = string
16+
is_enabled = optional(bool, true)
17+
namespace = string
18+
metric_compartment_id = optional(string)
19+
repeat_notification_duration = optional(string, "PT5M")
20+
trigger = optional(string, "PT5M")
21+
suppression_from_time = optional(string)
22+
suppression_till_time = optional(string)
23+
message_format = optional(string, "RAW")
24+
body = optional(string, null)
25+
freeform_tags = optional(map(string))
26+
defined_tags = optional(map(string))
27+
}))
28+
}
29+
30+
variable "notification" {
31+
description = "Notification Topic and Subscription"
32+
type = map(object({
33+
description = optional(string)
34+
create_topic = optional(bool, true)
35+
defined_tags = optional(map(string))
36+
freeform_tags = optional(map(string))
37+
subscription = map(object({
38+
endpoint = string
39+
protocol = string
40+
}))
41+
}))
42+
}
43+
44+
variable "label_prefix" {
45+
default = "none"
46+
description = "Prefix to be added to the resources"
47+
type = string
48+
}

modules/alarm/versions.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#Copyright (c) 2023 Oracle Corporation and/or its affiliates.
2+
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
3+
4+
terraform {
5+
required_providers {
6+
oci = {
7+
source = "oracle/oci"
8+
version = ">= 4.67.3"
9+
}
10+
}
11+
required_version = ">= 1.3.0"
12+
}

0 commit comments

Comments
 (0)