Skip to content

Commit

Permalink
feat: dashbaord obj submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavkumarsph committed Sep 25, 2024
1 parent 5c7bbbb commit 906e2bb
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 0 deletions.
42 changes: 42 additions & 0 deletions examples/dashboard/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
locals {
id = coalesce(var.pattern_id, split("-*", var.pattern)[0])
}

module "tenant" {
source = "../../modules/dashboard/tenant"

name = "test-tenant"
}

module "index_pattern" {
source = "../../modules/dashboard/index-pattern"

tenant_name = module.tenant.name
pattern = "test-*"
time_field_name = var.time_field_name
}

module "dashboard" {
source = "../../modules/dashboard/object"

tenant_name = module.tenant.name

body = <<EOF
[
{
"_id": "visualization:response-time-percentile",
"_type": "doc",
"_source": {
"type": "visualization",
"visualization": {
"title": "Total response time percentiles",
"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\":{}}",
"uiStateJSON": "{}",
"description": "",
"version": 1
}
}
}
]
EOF
}
2 changes: 2 additions & 0 deletions examples/dashboard/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
provider "opensearch" {
}
17 changes: 17 additions & 0 deletions examples/dashboard/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
variable "pattern" {
description = "The index pattern"
type = string
default = "test-pattern-*"
}

variable "pattern_id" {
description = "The ID of index pattern"
type = string
default = "test"
}

variable "time_field_name" {
description = "Field name which has the timestamp"
type = string
default = "timestamp"
}
10 changes: 10 additions & 0 deletions examples/dashboard/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"
}
}
}
4 changes: 4 additions & 0 deletions modules/dashboard/object/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "opensearch_dashboard_object" "this" {
tenant_name = var.tenant_name
body = jsonencode(var.body)
}
4 changes: 4 additions & 0 deletions modules/dashboard/object/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "id" {
description = "The ID of the object"
value = opensearch_dashboard_object.this.id
}
10 changes: 10 additions & 0 deletions modules/dashboard/object/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
variable "tenant_name" {
description = "The name of the tenant to which dashboard data associates. Empty string defaults to global tenant"
type = string
default = ""
}

variable "body" {
description = "The dashboard document in JSON or HCL"
type = any
}
10 changes: 10 additions & 0 deletions modules/dashboard/object/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"
}
}
}
5 changes: 5 additions & 0 deletions modules/dashboard/tenant/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ output "id" {
description = "The ID of the dashboard tenant"
value = opensearch_dashboard_tenant.this.id
}

output "name" {
description = "The name of the dashboard tenant"
value = opensearch_dashboard_tenant.this.tenant_name
}

0 comments on commit 906e2bb

Please sign in to comment.