Skip to content

Commit 8c3c2af

Browse files
authored
feat: added support to the DA to deploy and manage a Kibana instance in a code engine project. To enable, set enable_kibana_dashboard to true (#309)
1 parent bc0dc45 commit 8c3c2af

File tree

7 files changed

+131
-12
lines changed

7 files changed

+131
-12
lines changed

examples/basic/main.tf

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,18 @@ resource "time_sleep" "wait" {
3131
create_duration = "15s"
3232
}
3333

34-
resource "elasticsearch_index" "test" {
35-
depends_on = [time_sleep.wait]
36-
name = "terraform-test"
37-
number_of_shards = 1
38-
number_of_replicas = 1
39-
force_destroy = true
40-
}
34+
# Commenting below code to this issue https://github.com/terraform-ibm-modules/terraform-ibm-icd-elasticsearch/issues/317
4135

42-
resource "elasticsearch_cluster_settings" "global" {
43-
depends_on = [time_sleep.wait]
44-
cluster_max_shards_per_node = 10
45-
action_auto_create_index = "my-index-000001,index10,-index1*,+ind*"
46-
}
36+
# resource "elasticsearch_index" "test" {
37+
# depends_on = [time_sleep.wait]
38+
# name = "terraform-test"
39+
# number_of_shards = 1
40+
# number_of_replicas = 1
41+
# force_destroy = true
42+
# }
43+
44+
# resource "elasticsearch_cluster_settings" "global" {
45+
# depends_on = [time_sleep.wait]
46+
# cluster_max_shards_per_node = 10
47+
# action_auto_create_index = "my-index-000001,index10,-index1*,+ind*"
48+
# }

solutions/standard/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This architecture creates an instance of IBM Cloud Databases for Elasticsearch a
66
- A KMS root key, if one is not passed in.
77
- An IBM Cloud Databases for Elasticsearch instance with KMS encryption.
88
- Autoscaling rules for the database instance, if provided.
9+
- Kibana dashboard for Elasticsearch.
910

1011
![fscloud-elastic-search](../../reference-architecture/deployable-architecture-elasticsearch.svg)
1112

solutions/standard/main.tf

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,87 @@ data "ibm_database_connection" "existing_connection" {
232232
user_id = data.ibm_database.existing_db_instance[0].adminuser
233233
user_type = "database"
234234
}
235+
236+
########################################################################################################################
237+
# Code Engine Kibana Dashboard instance
238+
########################################################################################################################
239+
240+
locals {
241+
242+
code_engine_project_id = var.existing_code_engine_project_id != null ? var.existing_code_engine_project_id : null
243+
code_engine_project_name = local.code_engine_project_id != null ? null : var.prefix != null ? "${var.prefix}-code-engine-kibana-project" : "ce-kibana-project"
244+
code_engine_app_name = var.prefix != null ? "${var.prefix}-kibana-app" : "ce-kibana-app"
245+
246+
es_host = local.use_existing_db_instance ? data.ibm_database_connection.existing_connection[0].https[0].hosts[0].hostname : module.elasticsearch[0].hostname
247+
es_port = local.use_existing_db_instance ? data.ibm_database_connection.existing_connection[0].https[0].hosts[0].port : module.elasticsearch[0].port
248+
es_cert = local.use_existing_db_instance ? data.ibm_database_connection.existing_connection[0].https[0].certificate[0].certificate_base64 : module.elasticsearch[0].certificate_base64
249+
es_username = local.use_existing_db_instance ? data.ibm_database.existing_db_instance[0].adminuser : "admin"
250+
es_password = local.admin_pass
251+
es_data = var.enable_kibana_dashboard ? jsondecode(data.http.es_metadata[0].response_body) : null
252+
es_full_version = var.enable_kibana_dashboard ? (var.elasticsearch_full_version != null ? var.elasticsearch_full_version : local.es_data.version.number) : null
253+
254+
}
255+
256+
data "http" "es_metadata" {
257+
count = var.enable_kibana_dashboard ? 1 : 0
258+
url = "https://${local.es_username}:${local.es_password}@${local.es_host}:${local.es_port}"
259+
ca_cert_pem = base64decode(local.es_cert)
260+
}
261+
262+
module "code_engine_kibana" {
263+
count = var.enable_kibana_dashboard ? 1 : 0
264+
source = "terraform-ibm-modules/code-engine/ibm"
265+
version = "2.0.4"
266+
resource_group_id = module.resource_group.resource_group_id
267+
project_name = local.code_engine_project_name
268+
existing_project_id = local.code_engine_project_id
269+
secrets = {
270+
"es-secret" = {
271+
format = "generic"
272+
data = {
273+
"ELASTICSEARCH_PASSWORD" = local.es_password
274+
}
275+
}
276+
}
277+
278+
apps = {
279+
(local.code_engine_app_name) = {
280+
image_reference = "docker.elastic.co/kibana/kibana:${local.es_full_version}"
281+
image_port = 5601
282+
run_env_variables = [{
283+
type = "literal"
284+
name = "ELASTICSEARCH_HOSTS"
285+
value = "[\"https://${local.es_host}:${local.es_port}\"]"
286+
},
287+
{
288+
type = "literal"
289+
name = "ELASTICSEARCH_USERNAME"
290+
value = local.es_username
291+
},
292+
{
293+
type = "secret_key_reference"
294+
name = "ELASTICSEARCH_PASSWORD"
295+
key = "ELASTICSEARCH_PASSWORD"
296+
reference = "es-secret"
297+
},
298+
{
299+
type = "literal"
300+
name = "ELASTICSEARCH_SSL_ENABLED"
301+
value = "true"
302+
},
303+
{
304+
type = "literal"
305+
name = "SERVER_HOST"
306+
value = "0.0.0.0"
307+
},
308+
{
309+
type = "literal"
310+
name = "ELASTICSEARCH_SSL_VERIFICATIONMODE"
311+
value = "none"
312+
}
313+
]
314+
scale_min_instances = 1
315+
scale_max_instances = 3
316+
}
317+
}
318+
}

solutions/standard/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,8 @@ output "admin_pass" {
5959
value = local.admin_pass
6060
sensitive = true
6161
}
62+
63+
output "kibana_app_endpoint" {
64+
description = "Code Engine Kibana endpoint URL"
65+
value = var.enable_kibana_dashboard ? module.code_engine_kibana[0].app[local.code_engine_app_name].endpoint : null
66+
}

solutions/standard/variables.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,25 @@ variable "admin_pass_sm_secret_name" {
315315
description = "The name of a new elasticsearch administrator secret. If a prefix input variable is specified, the prefix is added to the name in the `<prefix>-<name>` format."
316316
default = "elasticsearch-admin-password"
317317
}
318+
319+
##############################################################
320+
# Kibana Configuration
321+
##############################################################
322+
323+
variable "existing_code_engine_project_id" {
324+
description = "Existing code engine project ID to deploy Kibana. If no value is passed, a new code engine project will be created."
325+
type = string
326+
default = null
327+
}
328+
329+
variable "enable_kibana_dashboard" {
330+
type = bool
331+
description = "Set it true to deploy Kibana in code engine. NOTE: Kibana image is coming direcly from the official registry (https://www.docker.elastic.co/) and not certified by the IBM."
332+
default = false
333+
}
334+
335+
variable "elasticsearch_full_version" {
336+
description = "(Optional) Full version of the Elasticsearch instance in the format `x.x.x` to deploy Kibana dashboard. If no value is passed, data lookup will fetch the full version using the Elasticsearch API, see https://github.com/elastic/kibana?tab=readme-ov-file#version-compatibility-with-elasticsearch"
337+
type = string
338+
default = null
339+
}

solutions/standard/version.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@ terraform {
1515
source = "hashicorp/random"
1616
version = "3.6.3"
1717
}
18+
http = {
19+
source = "hashicorp/http"
20+
version = "3.4.5"
21+
}
1822
}
1923
}

tests/pr_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ func TestRunStandardSolutionSchematics(t *testing.T) {
192192
{Name: "service_credential_secrets", Value: serviceCredentialSecrets, DataType: "list(object)"},
193193
{Name: "admin_pass_sm_secret_group", Value: options.Prefix, DataType: "string"},
194194
{Name: "admin_pass_sm_secret_name", Value: options.Prefix, DataType: "string"},
195+
{Name: "enable_kibana_dashboard", Value: true, DataType: "bool"},
195196
}
196197
err := options.RunSchematicTest()
197198
assert.Nil(t, err, "This should not have errored")

0 commit comments

Comments
 (0)