Skip to content

Commit 434f179

Browse files
fix: refactored the logic in the DA used to determine the kibana version (#526)
1 parent ab3a9f7 commit 434f179

File tree

6 files changed

+53
-11
lines changed

6 files changed

+53
-11
lines changed

.secrets.baseline

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "go.sum|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2025-10-11T11:57:05Z",
6+
"generated_at": "2025-10-15T14:30:02Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
@@ -110,7 +110,7 @@
110110
"hashed_secret": "8c7c51db5075ebd0369c51e9f14737d9b4c1c21d",
111111
"is_secret": false,
112112
"is_verified": false,
113-
"line_number": 413,
113+
"line_number": 415,
114114
"type": "Base64 High Entropy String",
115115
"verified_result": null
116116
}

solutions/fully-configurable/main.tf

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,15 +464,20 @@ locals {
464464
code_engine_project_id = var.existing_code_engine_project_id != null ? var.existing_code_engine_project_id : null
465465
code_engine_project_name = local.code_engine_project_id != null ? null : (var.prefix != null && var.prefix != "") ? "${var.prefix}-${var.kibana_code_engine_new_project_name}" : var.kibana_code_engine_new_project_name
466466
code_engine_app_name = (var.prefix != null && var.prefix != "") ? "${var.prefix}-${var.kibana_code_engine_new_app_name}" : var.kibana_code_engine_new_app_name
467-
kibana_version = var.enable_kibana_dashboard ? jsondecode(data.http.es_metadata[0].response_body).version.number : null
467+
kibana_version = var.enable_kibana_dashboard ? try(data.external.es_metadata[0].result.version_number, null) : null
468468
kibana_system_password = var.enable_kibana_dashboard ? startswith(random_password.kibana_system_password[0].result, "-") ? "J${substr(random_password.kibana_system_password[0].result, 1, -1)}" : startswith(random_password.kibana_system_password[0].result, "_") ? "K${substr(random_password.kibana_system_password[0].result, 1, -1)}" : random_password.kibana_system_password[0].result : null
469469
kibana_app_login_password = var.enable_kibana_dashboard ? startswith(random_password.kibana_app_login_password[0].result, "-") ? "J${substr(random_password.kibana_app_login_password[0].result, 1, -1)}" : startswith(random_password.kibana_app_login_password[0].result, "_") ? "K${substr(random_password.kibana_app_login_password[0].result, 1, -1)}" : random_password.kibana_app_login_password[0].result : null
470470
}
471471

472-
data "http" "es_metadata" {
473-
count = var.enable_kibana_dashboard ? 1 : 0
474-
url = "https://${local.elasticsearch_username}:${local.admin_pass}@${local.elasticsearch_hostname}:${local.elasticsearch_port}"
475-
ca_cert_pem = base64decode(local.elasticsearch_cert)
472+
data "external" "es_metadata" {
473+
count = var.enable_kibana_dashboard ? 1 : 0
474+
program = ["bash", "${path.module}/scripts/es_metadata.sh"]
475+
query = {
476+
url = "https://${local.elasticsearch_hostname}:${local.elasticsearch_port}"
477+
username = local.elasticsearch_username
478+
password = local.admin_pass
479+
ca_cert_b64 = local.elasticsearch_cert
480+
}
476481
}
477482

478483
module "code_engine_kibana" {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Read JSON from stdin
6+
INPUT_JSON="$(cat)"
7+
8+
# Extract fields using jq
9+
URL="$(echo "$INPUT_JSON" | jq -r '.url')"
10+
USERNAME="$(echo "$INPUT_JSON" | jq -r '.username')"
11+
PASSWORD="$(echo "$INPUT_JSON" | jq -r '.password')" # pragma: allowlist secret
12+
CA_CERT_B64="$(echo "$INPUT_JSON" | jq -r '.ca_cert_b64')"
13+
14+
# Extract host for .netrc "machine" entry
15+
HOST="$(echo "$URL" | sed -E 's#^https?://([^/:]+).*#\1#')"
16+
17+
RESP="$(
18+
curl -sS --fail \
19+
--netrc-file <(printf 'machine %s login %s password %s\n' \
20+
"$HOST" "$USERNAME" "$PASSWORD") \
21+
--cacert <(echo "$CA_CERT_B64" | base64 -d) \
22+
"$URL"
23+
)"
24+
25+
26+
VERSION_NUMBER="$(echo "$RESP" | jq -r '.version.number // empty')"
27+
28+
29+
if [[ -z "$VERSION_NUMBER" ]]; then
30+
echo '{"version_number":null}'
31+
else
32+
33+
SAFE_VERSION_NUMBER="${VERSION_NUMBER//\"/\\\"}"
34+
echo "{\"version_number\":\"$SAFE_VERSION_NUMBER\"}"
35+
fi

solutions/fully-configurable/version.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ terraform {
1414
source = "hashicorp/random"
1515
version = "3.7.2"
1616
}
17-
http = {
18-
source = "hashicorp/http"
19-
version = "3.5.0"
17+
external = {
18+
source = "hashicorp/external"
19+
version = "2.3.5"
2020
}
2121
}
2222
}

tests/pr_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func TestRunFullyConfigurableSolutionSchematics(t *testing.T) {
6969
TarIncludePatterns: []string{
7070
"*.tf",
7171
fmt.Sprintf("%s/*.tf", fullyConfigurableSolutionTerraformDir),
72+
fmt.Sprintf("%s/scripts/*.sh", fullyConfigurableSolutionTerraformDir),
7273
fmt.Sprintf("%s/*.sh", "scripts"),
7374
},
7475
TemplateFolder: fullyConfigurableSolutionTerraformDir,
@@ -201,6 +202,7 @@ func TestRunSecurityEnforcedSolutionSchematics(t *testing.T) {
201202
"*.tf",
202203
fmt.Sprintf("%s/*.tf", fullyConfigurableSolutionTerraformDir),
203204
fmt.Sprintf("%s/*.tf", securityEnforcedSolutionTerraformDir),
205+
fmt.Sprintf("%s/scripts/*.sh", fullyConfigurableSolutionTerraformDir),
204206
fmt.Sprintf("%s/*.sh", "scripts"),
205207
},
206208
TemplateFolder: securityEnforcedSolutionTerraformDir,

0 commit comments

Comments
 (0)