Skip to content

Commit 5c7bbbb

Browse files
feat: slack channel and monitor submodules (#52)
1 parent 890ebd7 commit 5c7bbbb

File tree

13 files changed

+243
-0
lines changed

13 files changed

+243
-0
lines changed

examples/notification/main.tf

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
module "slack_channel" {
2+
source = "../../modules/channel/slack"
3+
4+
id = "test_slack"
5+
name = "Test slack channel"
6+
webhook_url = "https://hooks.slack.com/services/test"
7+
}
8+
9+
module "monitor" {
10+
source = "../../modules/monitor"
11+
12+
body = {
13+
name = "test-monitor"
14+
type = "monitor"
15+
enabled = true
16+
17+
schedule = {
18+
period = {
19+
interval = 1
20+
unit = "MINUTES"
21+
}
22+
}
23+
24+
inputs = [
25+
{
26+
search = {
27+
indices = ["movies"]
28+
query = {
29+
size = 0
30+
aggregations = {}
31+
query = {
32+
bool = {
33+
adjust_pure_negative = true
34+
boost = 1
35+
36+
filter = [
37+
{
38+
range = {
39+
"@timestamp" = {
40+
boost = 1
41+
from = "||-1h"
42+
to = ""
43+
include_lower = true
44+
include_upper = true
45+
format = "epoch_millis"
46+
}
47+
}
48+
}
49+
]
50+
}
51+
}
52+
}
53+
}
54+
}
55+
]
56+
57+
triggers = [
58+
{
59+
name = "Errors"
60+
severity = "1"
61+
62+
condition = {
63+
script = {
64+
source = "ctx.results[0].hits.total.value > 0"
65+
lang = "painless"
66+
}
67+
}
68+
69+
actions = [
70+
{
71+
name = "Slack"
72+
destination_id = module.slack_channel.id
73+
throttle_enabled = false
74+
message_template = {
75+
source = "bogus"
76+
lang = "mustache"
77+
}
78+
subject_template = {
79+
source = "Production Errors"
80+
lang = "mustache"
81+
}
82+
}
83+
]
84+
}
85+
]
86+
}
87+
}

examples/notification/providers.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
provider "opensearch" {
2+
}

examples/notification/versions.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.4"
3+
4+
required_providers {
5+
opensearch = {
6+
source = "opensearch-project/opensearch"
7+
version = "~> 2.3.0"
8+
}
9+
}
10+
}

modules/channel/slack/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## Requirements
2+
3+
| Name | Version |
4+
|------|---------|
5+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.4 |
6+
| <a name="requirement_opensearch"></a> [opensearch](#requirement\_opensearch) | >= 2.0 |
7+
8+
## Providers
9+
10+
| Name | Version |
11+
|------|---------|
12+
| <a name="provider_opensearch"></a> [opensearch](#provider\_opensearch) | >= 2.0 |
13+
14+
## Modules
15+
16+
No modules.
17+
18+
## Resources
19+
20+
| Name | Type |
21+
|------|------|
22+
| [opensearch_channel_configuration.this](https://registry.terraform.io/providers/opensearch-project/opensearch/latest/docs/resources/channel_configuration) | resource |
23+
24+
## Inputs
25+
26+
| Name | Description | Type | Default | Required |
27+
|------|-------------|------|---------|:--------:|
28+
| <a name="input_description"></a> [description](#input\_description) | Channel config description | `string` | `""` | no |
29+
| <a name="input_id"></a> [id](#input\_id) | Channel config ID | `string` | n/a | yes |
30+
| <a name="input_name"></a> [name](#input\_name) | Channel config name | `string` | n/a | yes |
31+
| <a name="input_webhook_url"></a> [webhook\_url](#input\_webhook\_url) | Slack webhook URL | `string` | n/a | yes |
32+
33+
## Outputs
34+
35+
| Name | Description |
36+
|------|-------------|
37+
| <a name="output_id"></a> [id](#output\_id) | The ID of the channel configuration |

modules/channel/slack/main.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
resource "opensearch_channel_configuration" "this" {
2+
body = jsonencode(
3+
{
4+
config_id = var.id
5+
6+
config = {
7+
name = var.name
8+
description = var.description
9+
config_type = "slack"
10+
is_enabled = true
11+
12+
slack = {
13+
url = var.webhook_url
14+
}
15+
}
16+
}
17+
)
18+
}

modules/channel/slack/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "id" {
2+
description = "The ID of the channel configuration"
3+
value = opensearch_channel_configuration.this.id
4+
}

modules/channel/slack/variables.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
variable "name" {
2+
description = "Channel config name"
3+
type = string
4+
}
5+
6+
variable "id" {
7+
description = "Channel config ID"
8+
type = string
9+
}
10+
11+
variable "description" {
12+
description = "Channel config description"
13+
type = string
14+
default = ""
15+
}
16+
17+
variable "webhook_url" {
18+
description = "Slack webhook URL"
19+
type = string
20+
}

modules/channel/slack/versions.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.4"
3+
4+
required_providers {
5+
opensearch = {
6+
source = "opensearch-project/opensearch"
7+
version = ">= 2.0"
8+
}
9+
}
10+
}

modules/monitor/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## Requirements
2+
3+
| Name | Version |
4+
|------|---------|
5+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.4 |
6+
| <a name="requirement_opensearch"></a> [opensearch](#requirement\_opensearch) | >= 2.0 |
7+
8+
## Providers
9+
10+
| Name | Version |
11+
|------|---------|
12+
| <a name="provider_opensearch"></a> [opensearch](#provider\_opensearch) | >= 2.0 |
13+
14+
## Modules
15+
16+
No modules.
17+
18+
## Resources
19+
20+
| Name | Type |
21+
|------|------|
22+
| [opensearch_monitor.this](https://registry.terraform.io/providers/opensearch-project/opensearch/latest/docs/resources/monitor) | resource |
23+
24+
## Inputs
25+
26+
| Name | Description | Type | Default | Required |
27+
|------|-------------|------|---------|:--------:|
28+
| <a name="input_body"></a> [body](#input\_body) | The monitor document | `string` | n/a | yes |
29+
30+
## Outputs
31+
32+
| Name | Description |
33+
|------|-------------|
34+
| <a name="output_id"></a> [id](#output\_id) | The ID of the monitor |

modules/monitor/main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
resource "opensearch_monitor" "this" {
2+
body = jsonencode(var.body)
3+
}

modules/monitor/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "id" {
2+
description = "The ID of the monitor"
3+
value = opensearch_monitor.this.id
4+
}

modules/monitor/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
variable "body" {
2+
description = "The monitor document in HCL format"
3+
type = any
4+
}

modules/monitor/versions.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.4"
3+
4+
required_providers {
5+
opensearch = {
6+
source = "opensearch-project/opensearch"
7+
version = ">= 2.0"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)