Skip to content

Commit 40e185e

Browse files
feat: dashbaord obj submodule (#55)
1 parent f4567cc commit 40e185e

File tree

9 files changed

+94
-0
lines changed

9 files changed

+94
-0
lines changed

examples/dashboard/main.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module "tenant" {
2+
source = "../../modules/dashboard/tenant"
3+
4+
name = "test-tenant"
5+
}
6+
7+
module "index_pattern" {
8+
source = "../../modules/dashboard/index-pattern"
9+
10+
tenant_name = module.tenant.name
11+
pattern = var.pattern
12+
time_field_name = var.time_field_name
13+
}
14+
15+
module "dashboard" {
16+
source = "../../modules/dashboard/object"
17+
18+
tenant_name = module.tenant.name
19+
20+
body = <<EOF
21+
[
22+
{
23+
"_id": "visualization:response-time-percentile",
24+
"_type": "doc",
25+
"_source": {
26+
"type": "visualization",
27+
"visualization": {
28+
"title": "Total response time percentiles",
29+
"visState": "{\"title\":\"Total response time percentiles\",\"type\":\"line\",\"params\":{\"addTooltip\":true,\"addLegend\":true,\"legendPosition\":\"right\",\"showCircles\":true,\"interpolate\":\"linear\",\"scale\":\"linear\",\"drawLinesBetweenPoints\":true,\"radiusRatio\":9,\"times\":[],\"addTimeMarker\":false,\"defaultYExtents\":false,\"setYExtents\":false},\"aggs\":[{\"id\":\"1\",\"enabled\":true,\"type\":\"percentiles\",\"schema\":\"metric\",\"params\":{\"field\":\"app.total_time\",\"percents\":[50,90,95]}},{\"id\":\"2\",\"enabled\":true,\"type\":\"date_histogram\",\"schema\":\"segment\",\"params\":{\"field\":\"@timestamp\",\"interval\":\"auto\",\"customInterval\":\"2h\",\"min_doc_count\":1,\"extended_bounds\":{}}},{\"id\":\"3\",\"enabled\":true,\"type\":\"terms\",\"schema\":\"group\",\"params\":{\"field\":\"system.syslog.program\",\"size\":5,\"order\":\"desc\",\"orderBy\":\"_term\"}}],\"listeners\":{}}",
30+
"uiStateJSON": "{}",
31+
"description": "",
32+
"version": 1
33+
}
34+
}
35+
}
36+
]
37+
EOF
38+
}

examples/dashboard/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/dashboard/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
variable "pattern" {
2+
description = "The index pattern"
3+
type = string
4+
default = "test-pattern-*"
5+
}
6+
7+
variable "time_field_name" {
8+
description = "Field name which has the timestamp"
9+
type = string
10+
default = "timestamp"
11+
}

examples/dashboard/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/dashboard/object/main.tf

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

modules/dashboard/object/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 object"
3+
value = opensearch_dashboard_object.this.id
4+
}

modules/dashboard/object/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
variable "tenant_name" {
2+
description = "The name of the tenant to which dashboard data associates. Empty string defaults to global tenant"
3+
type = string
4+
default = ""
5+
}
6+
7+
variable "body" {
8+
description = "The dashboard document in JSON or HCL"
9+
type = any
10+
}

modules/dashboard/object/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/dashboard/tenant/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ output "id" {
22
description = "The ID of the dashboard tenant"
33
value = opensearch_dashboard_tenant.this.id
44
}
5+
6+
output "name" {
7+
description = "The name of the dashboard tenant"
8+
value = opensearch_dashboard_tenant.this.tenant_name
9+
}

0 commit comments

Comments
 (0)