Skip to content
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

Add multi-tenancy support #184

Merged
merged 2 commits into from
May 3, 2024

Conversation

PhilippReinke
Copy link
Contributor

@PhilippReinke PhilippReinke commented Apr 27, 2024

Description

A tenant_name argument has been added to the opensearch_dashboard_object resource. It's important to note that the global tenant is referenced by an empty string "" which is also the default value. Further,

  • a test case has been added
  • the code behind the opensearch_dashboard_object has been refactored
  • a CustomizeDiff function does now enforce a recreation of the resource when _id within the body changes. Previously, this did not work properly and a copy of the object was created without destroying the old one.

Note that using "global_tenant" as tenant creates an object in OpenSearch but it won't be visible in the UI. Hence, one needs to use "" to reference the global tenant.

Issues Resolved

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Philipp Reinke <[email protected]>
@PhilippReinke
Copy link
Contributor Author

PhilippReinke commented Apr 30, 2024

Could you please approve the workflow again ^^. A formatter was complaining about missing whitespaces in a Terraform snippet and I amended a fix for that.

@rblcoder
Copy link
Collaborator

rblcoder commented May 2, 2024

When I am testing using this docker compose file, https://opensearch.org/docs/latest/install-and-configure/install-opensearch/docker/#sample-docker-composeyml
I get the error

tenant_test_error

I have used the following Terraform code

terraform {
  required_providers {
    opensearch = {
      source = "opensearch-project/opensearch"
      version = "2.2.1"
    }
  }
}

provider "opensearch" {
  url = "https://localhost:9200"
  username          = "admin"
  password          = "myStrongPassword123@456"
  healthcheck = "false"
  insecure = "true"  
  version_ping_timeout = "10"

}

resource "opensearch_dashboard_tenant" "tenant_test" {
  tenant_name = "tenant_test"
  description = "tenant_test"
}

resource "opensearch_dashboard_object" "test_visualization" {
  depends_on = [
    opensearch_dashboard_tenant.tenant_test
  ]
  tenant_name = "tenant_test"
  body        = <<EOF
[
  {
    "_id": "response-time-percentile",
    "_source": {
      "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,
	      "dashboardSavedObjectMeta": {
	        "searchSourceJSON": "{\"index\":\"filebeat-*\",\"query\":{\"query_string\":{\"query\":\"*\",\"analyze_wildcard\":true}},\"filter\":[]}"
	      }
	    },
      "type": "visualization"
    }
  }
]
EOF
}

Is there any additional configuration required?

@PhilippReinke
Copy link
Contributor Author

PhilippReinke commented May 2, 2024

Hi @rblcoder :),

dashboardSavedObjectMeta needs to be replaced by kibanaSavedObjectMeta. With the latest OpenSearch version and sample data I can see under "Saved Objects / Edit visualization" that they changed it.

When I use your exact code snippets but kibanaSavedObjectMeta it works for me.

@rblcoder
Copy link
Collaborator

rblcoder commented May 2, 2024

@PhilippReinke Should the references to dashboardSavedObjectMeta in resource_opensearch_dashboard_object_test.go,
be changed to kibanaSavedObjectMeta?

The resource is successfully created now with this modification, though the Saved Objects / Edit Visualization fields are not populated with the data which is specified in the Terraform code.
saved_objects_empty

@PhilippReinke
Copy link
Contributor Author

PhilippReinke commented May 2, 2024

@rblcoder It doesn't work because you cannot have a visualization without index-pattern. By default you've got an index of the form "security-auditlog-*" and the following example shows how to then define a visualization for it.

resource "opensearch_dashboard_tenant" "tenant_test" {
  tenant_name = "tenant_test"
  description = "tenant_test"
}

resource "opensearch_dashboard_object" "test_pattern" {
  depends_on = [
    opensearch_dashboard_tenant.tenant_test
  ]
  tenant_name = "tenant_test"
  body = <<EOF
[
  {
    "_id": "index-pattern:test_pattern",
    "_source": {
      "index-pattern": {
        "title": "security-auditlog-*",
        "timeFieldName": "@timestamp",
        "fields": "[{\"count\":0,\"name\":\"@timestamp\",\"type\":\"date\",\"esTypes\":[\"date\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true},{\"count\":0,\"name\":\"_id\",\"type\":\"string\",\"esTypes\":[\"_id\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":false},{\"count\":0,\"name\":\"_index\",\"type\":\"string\",\"esTypes\":[\"_index\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":false},{\"count\":0,\"name\":\"_score\",\"type\":\"number\",\"scripted\":false,\"searchable\":false,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"_source\",\"type\":\"_source\",\"esTypes\":[\"_source\"],\"scripted\":false,\"searchable\":false,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"_type\",\"type\":\"string\",\"scripted\":false,\"searchable\":false,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_category\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_category.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_category\"}}},{\"count\":0,\"name\":\"audit_cluster_name\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_cluster_name.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_cluster_name\"}}},{\"count\":0,\"name\":\"audit_compliance_doc_version\",\"type\":\"number\",\"esTypes\":[\"long\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true},{\"count\":0,\"name\":\"audit_compliance_operation\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_compliance_operation.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_compliance_operation\"}}},{\"count\":0,\"name\":\"audit_format_version\",\"type\":\"number\",\"esTypes\":[\"long\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true},{\"count\":0,\"name\":\"audit_node_host_address\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_node_host_address.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_node_host_address\"}}},{\"count\":0,\"name\":\"audit_node_host_name\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_node_host_name.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_node_host_name\"}}},{\"count\":0,\"name\":\"audit_node_id\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_node_id.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_node_id\"}}},{\"count\":0,\"name\":\"audit_node_name\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_node_name.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_node_name\"}}},{\"count\":0,\"name\":\"audit_request_body\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_request_body.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_request_body\"}}},{\"count\":0,\"name\":\"audit_request_effective_user\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_request_effective_user.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_request_effective_user\"}}},{\"count\":0,\"name\":\"audit_request_effective_user_is_admin\",\"type\":\"boolean\",\"esTypes\":[\"boolean\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true},{\"count\":0,\"name\":\"audit_request_layer\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_request_layer.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_request_layer\"}}},{\"count\":0,\"name\":\"audit_request_origin\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_request_origin.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_request_origin\"}}},{\"count\":0,\"name\":\"audit_request_privilege\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_request_privilege.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_request_privilege\"}}},{\"count\":0,\"name\":\"audit_request_remote_address\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_request_remote_address.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_request_remote_address\"}}},{\"count\":0,\"name\":\"audit_rest_request_headers.Accept\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_rest_request_headers.Accept-Encoding\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_rest_request_headers.Accept-Encoding.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_rest_request_headers.Accept-Encoding\"}}},{\"count\":0,\"name\":\"audit_rest_request_headers.Accept-Language\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_rest_request_headers.Accept-Language.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_rest_request_headers.Accept-Language\"}}},{\"count\":0,\"name\":\"audit_rest_request_headers.Accept.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_rest_request_headers.Accept\"}}},{\"count\":0,\"name\":\"audit_rest_request_headers.Connection\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_rest_request_headers.Connection.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_rest_request_headers.Connection\"}}},{\"count\":0,\"name\":\"audit_rest_request_headers.Cookie\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_rest_request_headers.Cookie.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_rest_request_headers.Cookie\"}}},{\"count\":0,\"name\":\"audit_rest_request_headers.Host\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_rest_request_headers.Host.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_rest_request_headers.Host\"}}},{\"count\":0,\"name\":\"audit_rest_request_headers.Sec-Fetch-Dest\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_rest_request_headers.Sec-Fetch-Dest.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_rest_request_headers.Sec-Fetch-Dest\"}}},{\"count\":0,\"name\":\"audit_rest_request_headers.Sec-Fetch-Mode\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_rest_request_headers.Sec-Fetch-Mode.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_rest_request_headers.Sec-Fetch-Mode\"}}},{\"count\":0,\"name\":\"audit_rest_request_headers.Sec-Fetch-Site\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_rest_request_headers.Sec-Fetch-Site.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_rest_request_headers.Sec-Fetch-Site\"}}},{\"count\":0,\"name\":\"audit_rest_request_headers.Sec-Fetch-User\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_rest_request_headers.Sec-Fetch-User.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_rest_request_headers.Sec-Fetch-User\"}}},{\"count\":0,\"name\":\"audit_rest_request_headers.Sec-GPC\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_rest_request_headers.Sec-GPC.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_rest_request_headers.Sec-GPC\"}}},{\"count\":0,\"name\":\"audit_rest_request_headers.Upgrade-Insecure-Requests\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_rest_request_headers.Upgrade-Insecure-Requests.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_rest_request_headers.Upgrade-Insecure-Requests\"}}},{\"count\":0,\"name\":\"audit_rest_request_headers.User-Agent\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_rest_request_headers.User-Agent.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_rest_request_headers.User-Agent\"}}},{\"count\":0,\"name\":\"audit_rest_request_headers.sec-ch-ua\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_rest_request_headers.sec-ch-ua-mobile\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_rest_request_headers.sec-ch-ua-mobile.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_rest_request_headers.sec-ch-ua-mobile\"}}},{\"count\":0,\"name\":\"audit_rest_request_headers.sec-ch-ua-platform\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_rest_request_headers.sec-ch-ua-platform.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_rest_request_headers.sec-ch-ua-platform\"}}},{\"count\":0,\"name\":\"audit_rest_request_headers.sec-ch-ua.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_rest_request_headers.sec-ch-ua\"}}},{\"count\":0,\"name\":\"audit_rest_request_method\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_rest_request_method.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_rest_request_method\"}}},{\"count\":0,\"name\":\"audit_rest_request_path\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_rest_request_path.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_rest_request_path\"}}},{\"count\":0,\"name\":\"audit_trace_doc_id\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_trace_doc_id.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_trace_doc_id\"}}},{\"count\":0,\"name\":\"audit_trace_indices\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_trace_indices.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_trace_indices\"}}},{\"count\":0,\"name\":\"audit_trace_resolved_indices\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_trace_resolved_indices.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_trace_resolved_indices\"}}},{\"count\":0,\"name\":\"audit_trace_shard_id\",\"type\":\"number\",\"esTypes\":[\"long\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true},{\"count\":0,\"name\":\"audit_trace_task_id\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_trace_task_id.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_trace_task_id\"}}},{\"count\":0,\"name\":\"audit_transport_headers.X-Opaque-Id\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_transport_headers.X-Opaque-Id.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_transport_headers.X-Opaque-Id\"}}},{\"count\":0,\"name\":\"audit_transport_headers._opendistro_security_initial_action_class_header\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_transport_headers._opendistro_security_initial_action_class_header.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_transport_headers._opendistro_security_initial_action_class_header\"}}},{\"count\":0,\"name\":\"audit_transport_headers._opendistro_security_origin_header\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_transport_headers._opendistro_security_origin_header.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_transport_headers._opendistro_security_origin_header\"}}},{\"count\":0,\"name\":\"audit_transport_headers._opendistro_security_remotecn\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_transport_headers._opendistro_security_remotecn.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_transport_headers._opendistro_security_remotecn\"}}},{\"count\":0,\"name\":\"audit_transport_request_type\",\"type\":\"string\",\"esTypes\":[\"text\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"audit_transport_request_type.keyword\",\"type\":\"string\",\"esTypes\":[\"keyword\"],\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true,\"subType\":{\"multi\":{\"parent\":\"audit_transport_request_type\"}}}]"
      },
      "type": "index-pattern",
      "references": []
    }
  }
]
EOF
}

resource "opensearch_dashboard_object" "test_visualization" {
  depends_on = [
    opensearch_dashboard_tenant.tenant_test,
    opensearch_dashboard_object.test_pattern
  ]
  tenant_name = "tenant_test"
  body        = <<EOF
[
  {
    "_id": "visualization:test_visualization",
    "_source": {
      "visualization": {
        "title": "Test Visualization",
        "visState": "{\"title\":\"Test Visualization\",\"type\":\"table\",\"aggs\":[{\"id\":\"1\",\"enabled\":true,\"type\":\"count\",\"params\":{},\"schema\":\"metric\"}],\"params\":{\"perPage\":10,\"showPartialRows\":false,\"showMetricsAtAllLevels\":false,\"showTotal\":false,\"totalFunc\":\"sum\",\"percentageCol\":\"\"}}",
        "uiStateJSON": "{}",
        "description": "",
        "version": 1,
        "kibanaSavedObjectMeta": {
          "searchSourceJSON": "{\"query\":{\"query\":\"\",\"language\":\"kuery\"},\"filter\":[],\"indexRefName\":\"kibanaSavedObjectMeta.searchSourceJSON.index\"}"
        }
      },
      "type": "visualization",
      "references": [
        {
          "name": "kibanaSavedObjectMeta.searchSourceJSON.index",
          "type": "index-pattern",
          "id": "${split(":", opensearch_dashboard_object.test_pattern.id)[1]}"
        }
      ]
    }
  }
]
EOF
}

As soon as there is something wrong with the definition of the object OpenSearch Dashboard won't display it correctly. In your example above the Dashboard shows no data but if you check the object via Dev Tools with

GET .kibana/_doc/<put index here>

you will see that object actually has been created with the values.

Kibana has a Saved objects API but there is non documented for OpenSearch Dashboard. Probably, this would be the better approach to manage Dashboard objects. However, as long as the API is not documented this PR offers a way to create objects per tenant.

@rblcoder
Copy link
Collaborator

rblcoder commented May 3, 2024

Thank you @PhilippReinke for the complete and detailed example.

Copy link
Collaborator

@rblcoder rblcoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes work for me.

@prudhvigodithi
Copy link
Member

Thanks for your contribution @PhilippReinke and thanks for reviewing @rblcoder.
@bbarani

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants