Skip to content

Initial commit #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Local .terraform directories
**/.terraform/*

provider.tf

# .tfstate files
*.tfstate
*.tfstate.*

# .tfvars files
*.tfvars
*.tfvars.json

# Crash log files
crash.log
crash.*.log

# visual code
**/.vscode/*
.DS_Store

.terraform.lock.hcl

# Ignore CLI configuration files
.terraformrc
terraform.rc
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
*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.*
# Oracle Cloud Infrastructure Terraform Module for Observability

# Project name

*Describe your project's features, functionality and target audience*
*This module is for creating resources related to Observability in Oracle Cloud Infrastructure*

## Installation

Expand All @@ -22,8 +20,6 @@

## Contributing

*If your project has specific contribution requirements, update the CONTRIBUTING.md file to ensure those requirements are clearly explained*

This project welcomes contributions from the community. Before submitting a pull request, please [review our contribution guide](./CONTRIBUTING.md)

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

## License

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

Copyright (c) 2023 Oracle and/or its affiliates.

*Replace this statement if your project is not licensed under the UPL*

Released under the Universal Permissive License v1.0 as shown at
<https://oss.oracle.com/licenses/upl/>.
31 changes: 31 additions & 0 deletions examples/alarm/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module "alarm" {
source = "./modules/alarm"
alarm_def = local.alarm_def
compartment_ocid = local.compartment_ocid
notification = local.notification

}

locals {
compartment_ocid = "<compartment id where notification and alarm will be created>"
notification = {
demotopic = {
subscription = {
sub1 = {
protocol = "EMAIL"
endpoint = "<email address>"
}
}
freeform_tags = {
env = "test"
}
}
}
alarm_def = {
"testdelete" = {
destination = "demotopic"
namespace = "oci_computeagent"
query = "CpuUtilization[1m].mean() > 70"
}
}
}
19 changes: 19 additions & 0 deletions examples/alarm/provider.tf.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
provider "oci" {
region = "<region where alarm,notification to be created>"
fingerprint = ""
private_key_path = ""

tenancy_ocid = ""
user_ocid = ""

}

terraform {
required_providers {
oci = {
source = "oracle/oci"
version = ">= 4.67.3"
}
}
required_version = ">= 1.3.0"
}
38 changes: 38 additions & 0 deletions examples/serviceconnector/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module "svc" {
source = "./modules/serviceconnector"
service_connector_def = local.service_connector_def
policy_compartment_id = local.policy_compartment_id
dynamic_group = local.dynamic_group

tenancy_ocid = local.tenancy_ocid
providers = {
oci.home = oci.home
}

}

locals {
tenancy_ocid = "<tenancy_ocid>"
dynamic_group = {
dg1 = { compartment_id = "<service connector compartment id>" }
}
policy_compartment_id = "<policy compartment>" #if not set policy will be created default in root compartment
service_connector_def = { sch2 = {
compartment_id = "<service connector compartment id>"
#If policy needs to be created set the below two values. By default its set to false to not create policy
#Set create_policy to true
#set dynamic group name with respect to service connector compartment
create_policy = true
dynamic_group_name = "<dynamicgroupname>"

sch_source = "streaming"
sch_target = "objectstorage"
display_name = "sch2"

stream_id = "existing stream ocid"
target = {
bucket = "<bucket name>"
}
}
}
}
30 changes: 30 additions & 0 deletions examples/serviceconnector/provider.tf.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
provider "oci" {
region = "<region where service connector to be created>"
fingerprint = ""
private_key_path = ""

tenancy_ocid = ""
user_ocid = ""

}

provider "oci" {
alias = "home"
region = "<region>"
fingerprint = ""
private_key_path = ""

tenancy_ocid = ""
user_ocid = ""

}

terraform {
required_providers {
oci = {
source = "oracle/oci"
version = ">= 4.67.3"
}
}
required_version = ">= 1.3.0"
}
42 changes: 42 additions & 0 deletions modules/alarm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
| <a name="requirement_oci"></a> [oci](#requirement\_oci) | >= 4.67.3 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_oci"></a> [oci](#provider\_oci) | >= 4.67.3 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [oci_monitoring_alarm.this](https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/monitoring_alarm) | resource |
| [oci_ons_notification_topic.this](https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/ons_notification_topic) | resource |
| [oci_ons_subscription.this](https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/ons_subscription) | resource |
| [oci_ons_notification_topics.existing_topic](https://registry.terraform.io/providers/oracle/oci/latest/docs/data-sources/ons_notification_topics) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <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 |
| <a name="input_compartment_ocid"></a> [compartment\_ocid](#input\_compartment\_ocid) | Compartment OCID | `string` | n/a | yes |
| <a name="input_label_prefix"></a> [label\_prefix](#input\_label\_prefix) | Prefix to be added to the resources | `string` | `"none"` | no |
| <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 |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_topic_ids"></a> [topic\_ids](#output\_topic\_ids) | Notification Topic OCID |
<!-- END_TF_DOCS -->
76 changes: 76 additions & 0 deletions modules/alarm/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#Copyright (c) 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

resource "oci_ons_notification_topic" "this" {
for_each = { for k, v in var.notification : k => v if v.create_topic == true }
compartment_id = var.compartment_ocid
name = var.label_prefix == "none" ? each.key : format("%s_%s", var.label_prefix, each.key)

description = each.value.description == null ? format("%s%s", each.key, " topic created by Terraform") : each.value.description
defined_tags = each.value.defined_tags
freeform_tags = each.value.freeform_tags

}

data "oci_ons_notification_topics" "existing_topic" {
for_each = { for k, v in var.notification : k => v if v.create_topic == false }

compartment_id = var.compartment_ocid

name = each.key
state = "ACTIVE"
}

resource "oci_ons_subscription" "this" {
for_each = { for v in local.notification_subscription : v.subscription => v }
compartment_id = var.compartment_ocid
endpoint = each.value.endpoint
protocol = each.value.protocol
topic_id = each.value.topic_id


defined_tags = each.value.defined_tags
freeform_tags = each.value.freeform_tags
}

resource "oci_monitoring_alarm" "this" {
for_each = length(var.alarm_def) > 0 ? var.alarm_def : {}
compartment_id = var.compartment_ocid
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)]
display_name = var.label_prefix == "none" ? each.key : format("%s_%s", var.label_prefix, each.key)
is_enabled = each.value.is_enabled
metric_compartment_id = each.value.metric_compartment_id == null ? var.compartment_ocid : each.value.metric_compartment
namespace = each.value.namespace
query = each.value.query
severity = each.value.severity
message_format = each.value.message_format
repeat_notification_duration = each.value.repeat_notification_duration
pending_duration = each.value.trigger
body = each.value.body
defined_tags = each.value.defined_tags
freeform_tags = each.value.freeform_tags
dynamic "suppression" {
for_each = (each.value.suppression_from_time != null && each.value.suppression_till_time != null) ? [1] : []
content {
time_suppress_from = each.value.suppression_from_time
time_suppress_until = each.value.suppression_till_time
}
}

}


locals {
notification_subscription = flatten([
for topic_key, topic_value in var.notification : [
for subscription_key, subscription_value in topic_value.subscription : {
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
protocol = subscription_value.protocol
endpoint = subscription_value.endpoint
subscription = format("%s_%s", topic_key, subscription_key)
defined_tags = topic_value.defined_tags
freeform_tags = topic_value.freeform_tags
}
]
])
}
7 changes: 7 additions & 0 deletions modules/alarm/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#Copyright (c) 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

output "topic_ids" {
description = "Notification Topic OCID"
value = { for k in oci_ons_notification_topic.this : k.name => k.topic_id }
}
48 changes: 48 additions & 0 deletions modules/alarm/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#Copyright (c) 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

variable "compartment_ocid" {
description = "Compartment OCID"
type = string
}


variable "alarm_def" {
description = "OCI Alarm definition"
type = map(object({
destination = string
severity = optional(string, "CRITICAL")
query = string
is_enabled = optional(bool, true)
namespace = string
metric_compartment_id = optional(string)
repeat_notification_duration = optional(string, "PT5M")
trigger = optional(string, "PT5M")
suppression_from_time = optional(string)
suppression_till_time = optional(string)
message_format = optional(string, "RAW")
body = optional(string, null)
freeform_tags = optional(map(string))
defined_tags = optional(map(string))
}))
}

variable "notification" {
description = "Notification Topic and Subscription"
type = map(object({
description = optional(string)
create_topic = optional(bool, true)
defined_tags = optional(map(string))
freeform_tags = optional(map(string))
subscription = map(object({
endpoint = string
protocol = string
}))
}))
}

variable "label_prefix" {
default = "none"
description = "Prefix to be added to the resources"
type = string
}
12 changes: 12 additions & 0 deletions modules/alarm/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#Copyright (c) 2023 Oracle Corporation and/or its affiliates.
#Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

terraform {
required_providers {
oci = {
source = "oracle/oci"
version = ">= 4.67.3"
}
}
required_version = ">= 1.3.0"
}
Loading