Skip to content

Commit

Permalink
feat: slack channel and monitor submodules (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavkumarsph authored Jul 30, 2024
1 parent 890ebd7 commit 5c7bbbb
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 0 deletions.
87 changes: 87 additions & 0 deletions examples/notification/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
module "slack_channel" {
source = "../../modules/channel/slack"

id = "test_slack"
name = "Test slack channel"
webhook_url = "https://hooks.slack.com/services/test"
}

module "monitor" {
source = "../../modules/monitor"

body = {
name = "test-monitor"
type = "monitor"
enabled = true

schedule = {
period = {
interval = 1
unit = "MINUTES"
}
}

inputs = [
{
search = {
indices = ["movies"]
query = {
size = 0
aggregations = {}
query = {
bool = {
adjust_pure_negative = true
boost = 1

filter = [
{
range = {
"@timestamp" = {
boost = 1
from = "||-1h"
to = ""
include_lower = true
include_upper = true
format = "epoch_millis"
}
}
}
]
}
}
}
}
}
]

triggers = [
{
name = "Errors"
severity = "1"

condition = {
script = {
source = "ctx.results[0].hits.total.value > 0"
lang = "painless"
}
}

actions = [
{
name = "Slack"
destination_id = module.slack_channel.id
throttle_enabled = false
message_template = {
source = "bogus"
lang = "mustache"
}
subject_template = {
source = "Production Errors"
lang = "mustache"
}
}
]
}
]
}
}
2 changes: 2 additions & 0 deletions examples/notification/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
provider "opensearch" {
}
10 changes: 10 additions & 0 deletions examples/notification/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.4"

required_providers {
opensearch = {
source = "opensearch-project/opensearch"
version = "~> 2.3.0"
}
}
}
37 changes: 37 additions & 0 deletions modules/channel/slack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.4 |
| <a name="requirement_opensearch"></a> [opensearch](#requirement\_opensearch) | >= 2.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_opensearch"></a> [opensearch](#provider\_opensearch) | >= 2.0 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [opensearch_channel_configuration.this](https://registry.terraform.io/providers/opensearch-project/opensearch/latest/docs/resources/channel_configuration) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_description"></a> [description](#input\_description) | Channel config description | `string` | `""` | no |
| <a name="input_id"></a> [id](#input\_id) | Channel config ID | `string` | n/a | yes |
| <a name="input_name"></a> [name](#input\_name) | Channel config name | `string` | n/a | yes |
| <a name="input_webhook_url"></a> [webhook\_url](#input\_webhook\_url) | Slack webhook URL | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_id"></a> [id](#output\_id) | The ID of the channel configuration |
18 changes: 18 additions & 0 deletions modules/channel/slack/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "opensearch_channel_configuration" "this" {
body = jsonencode(
{
config_id = var.id

config = {
name = var.name
description = var.description
config_type = "slack"
is_enabled = true

slack = {
url = var.webhook_url
}
}
}
)
}
4 changes: 4 additions & 0 deletions modules/channel/slack/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "id" {
description = "The ID of the channel configuration"
value = opensearch_channel_configuration.this.id
}
20 changes: 20 additions & 0 deletions modules/channel/slack/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
variable "name" {
description = "Channel config name"
type = string
}

variable "id" {
description = "Channel config ID"
type = string
}

variable "description" {
description = "Channel config description"
type = string
default = ""
}

variable "webhook_url" {
description = "Slack webhook URL"
type = string
}
10 changes: 10 additions & 0 deletions modules/channel/slack/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.4"

required_providers {
opensearch = {
source = "opensearch-project/opensearch"
version = ">= 2.0"
}
}
}
34 changes: 34 additions & 0 deletions modules/monitor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.4 |
| <a name="requirement_opensearch"></a> [opensearch](#requirement\_opensearch) | >= 2.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_opensearch"></a> [opensearch](#provider\_opensearch) | >= 2.0 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [opensearch_monitor.this](https://registry.terraform.io/providers/opensearch-project/opensearch/latest/docs/resources/monitor) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_body"></a> [body](#input\_body) | The monitor document | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_id"></a> [id](#output\_id) | The ID of the monitor |
3 changes: 3 additions & 0 deletions modules/monitor/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "opensearch_monitor" "this" {
body = jsonencode(var.body)
}
4 changes: 4 additions & 0 deletions modules/monitor/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "id" {
description = "The ID of the monitor"
value = opensearch_monitor.this.id
}
4 changes: 4 additions & 0 deletions modules/monitor/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "body" {
description = "The monitor document in HCL format"
type = any
}
10 changes: 10 additions & 0 deletions modules/monitor/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.4"

required_providers {
opensearch = {
source = "opensearch-project/opensearch"
version = ">= 2.0"
}
}
}

0 comments on commit 5c7bbbb

Please sign in to comment.