Skip to content

Commit b2cf470

Browse files
feat: Updates: <br>- Add binaries installation support in scripts for HashiCorp Waypoint runtime compatibility <br>- use terraform_data resource in-place of null_resource for improved Terraform resource handling (#609)
1 parent 3fcde39 commit b2cf470

File tree

12 files changed

+107
-18
lines changed

12 files changed

+107
-18
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": "2026-02-25T20:47:40Z",
6+
"generated_at": "2026-03-10T09:52:57Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
@@ -110,7 +110,7 @@
110110
"hashed_secret": "0b4fa8c4bcd22d61d35ced7462e18292e87ff633",
111111
"is_secret": false,
112112
"is_verified": false,
113-
"line_number": 427,
113+
"line_number": 428,
114114
"type": "Base64 High Entropy String",
115115
"verified_result": null
116116
}

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ You need the following permissions to run this module.
6666
|------|---------|
6767
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.9.0 |
6868
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.79.2, <2.0.0 |
69-
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 3.2.1, < 4.0.0 |
7069
| <a name="requirement_time"></a> [time](#requirement\_time) | >= 0.9.1, < 1.0.0 |
7170

7271
### Modules
@@ -87,8 +86,9 @@ You need the following permissions to run this module.
8786
| [ibm_iam_authorization_policy.kms_policy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
8887
| [ibm_resource_key.service_credentials](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/resource_key) | resource |
8988
| [ibm_resource_tag.elasticsearch_tag](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/resource_tag) | resource |
90-
| [null_resource.put_vectordb_model](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
91-
| [null_resource.start_vectordb_model](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
89+
| [terraform_data.install_required_binaries](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource |
90+
| [terraform_data.put_vectordb_model](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource |
91+
| [terraform_data.start_vectordb_model](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource |
9292
| [time_sleep.wait_for_authorization_policy](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
9393
| [time_sleep.wait_for_backup_kms_authorization_policy](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
9494
| [ibm_database_connection.database_connection](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/database_connection) | data source |
@@ -111,6 +111,7 @@ You need the following permissions to run this module.
111111
| <a name="input_elasticsearch_version"></a> [elasticsearch\_version](#input\_elasticsearch\_version) | The version of Databases for Elasticsearch to deploy. Possible values: `8.7`, `8.10`, `8.12`, `8.15`, `8.19`, `9.1` which requires an Enterprise Platinum pricing plan. If no value is specified, the current preferred version for IBM Cloud Databases is used. | `string` | `null` | no |
112112
| <a name="input_elser_model_type"></a> [elser\_model\_type](#input\_elser\_model\_type) | Trained ELSER model to be used for Elastic's Natural Language Processing. Possible values: `.elser_model_1`, `.elser_model_2` and `.elser_model_2_linux-x86_64`. Applies only if also 'plan' is set to 'platinum'. [Learn more](https://www.elastic.co/guide/en/machine-learning/current/ml-nlp-elser.html) | `string` | `".elser_model_2_linux-x86_64"` | no |
113113
| <a name="input_enable_elser_model"></a> [enable\_elser\_model](#input\_enable\_elser\_model) | Set it to true to install and start the Elastic's Natural Language Processing model. Applies only if also 'plan' is set to 'platinum'. [Learn more](https://cloud.ibm.com/docs/databases-for-elasticsearch?topic=databases-for-elasticsearch-elser-embeddings-elasticsearch) | `bool` | `false` | no |
114+
| <a name="input_install_required_binaries"></a> [install\_required\_binaries](#input\_install\_required\_binaries) | When set to true, a script will run to check if `jq` exist on the runtime and if not attempt to download it from the public internet and install it to /tmp. Set to false to skip running this script. | `bool` | `true` | no |
114115
| <a name="input_kms_key_crn"></a> [kms\_key\_crn](#input\_kms\_key\_crn) | The CRN of a Key Protect or Hyper Protect Crypto Services encryption key to encrypt your data. Applies only if `use_ibm_owned_encryption_key` is false. By default this key is used for both deployment data and backups, but this behaviour can be altered using the `use_same_kms_key_for_backups` and `backup_encryption_key_crn` inputs. Bare in mind that backups encryption is only available in certain regions. See [Bring your own key for backups](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-key-protect&interface=ui#key-byok) and [Using the HPCS Key for Backup encryption](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-hpcs#use-hpcs-backups). | `string` | `null` | no |
115116
| <a name="input_member_host_flavor"></a> [member\_host\_flavor](#input\_member\_host\_flavor) | Allocated host flavor per member. [Learn more](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/database#host_flavor). | `string` | `null` | no |
116117
| <a name="input_members"></a> [members](#input\_members) | The number of members that are allocated. [Learn more](https://cloud.ibm.com/docs/databases-for-elasticsearch?topic=databases-for-elasticsearch-resources-scaling). | `number` | `3` | no |

ibm_catalog.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,10 @@
603603
]
604604
}
605605
}
606+
},
607+
{
608+
"key": "install_required_binaries",
609+
"hidden": true
606610
}
607611
],
608612
"terraform_version": "1.12.2",

main.tf

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,15 +406,29 @@ locals {
406406
es_username = local.es_admin_user != null ? local.service_credentials_object["credentials"][local.es_admin_user]["username"] : var.admin_pass != null ? "admin" : null
407407
es_password = local.es_admin_user != null ? local.service_credentials_object["credentials"][local.es_admin_user]["password"] : var.admin_pass != null ? ibm_database.elasticsearch.adminpassword : null
408408
es_url = local.es_username != null && local.es_password != null ? "https://${local.es_username}:${local.es_password}@${data.ibm_database_connection.database_connection.https[0].hosts[0].hostname}:${data.ibm_database_connection.database_connection.https[0].hosts[0].port}" : null
409+
binaries_path = "/tmp"
409410
}
410411

411-
resource "null_resource" "put_vectordb_model" {
412-
count = var.enable_elser_model ? 1 : 0
413-
triggers = {
412+
resource "terraform_data" "install_required_binaries" {
413+
count = var.install_required_binaries && var.enable_elser_model ? 1 : 0
414+
triggers_replace = {
415+
file_changed = md5(var.elser_model_type)
416+
}
417+
418+
provisioner "local-exec" {
419+
command = "${path.module}/solutions/fully-configurable/scripts/install-binaries.sh ${local.binaries_path}"
420+
interpreter = ["/bin/bash", "-c"]
421+
}
422+
}
423+
424+
resource "terraform_data" "put_vectordb_model" {
425+
depends_on = [terraform_data.install_required_binaries]
426+
count = var.enable_elser_model ? 1 : 0
427+
triggers_replace = {
414428
file_changed = md5(var.elser_model_type)
415429
}
416430
provisioner "local-exec" {
417-
command = "${path.module}/scripts/put_vectordb_model.sh"
431+
command = "${path.module}/scripts/put_vectordb_model.sh ${local.binaries_path}"
418432
interpreter = ["/bin/bash", "-c"]
419433
environment = {
420434
ES = local.es_url
@@ -423,10 +437,10 @@ resource "null_resource" "put_vectordb_model" {
423437
}
424438
}
425439

426-
resource "null_resource" "start_vectordb_model" {
427-
depends_on = [null_resource.put_vectordb_model]
440+
resource "terraform_data" "start_vectordb_model" {
441+
depends_on = [terraform_data.put_vectordb_model]
428442
count = var.enable_elser_model ? 1 : 0
429-
triggers = {
443+
triggers_replace = {
430444
file_changed = md5(var.elser_model_type)
431445
}
432446
provisioner "local-exec" {

scripts/put_vectordb_model.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/bin/bash
22
set -e
33

4+
# The binaries downloaded by the install-binaries script are located in the /tmp directory.
5+
export PATH=$PATH:${1:-"/tmp"}
6+
47
INSTALL_NEW_MODEL=true
58

69
# get trained models from elasticsearch

solutions/fully-configurable/main.tf

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,18 @@ locals {
469469
kibana_version = var.enable_kibana_dashboard ? try(data.external.es_metadata[0].result.version_number, null) : null
470470
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
471471
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
472+
binaries_path = "/tmp"
473+
}
474+
475+
data "external" "install_required_binaries" {
476+
count = var.install_required_binaries && var.enable_kibana_dashboard ? 1 : 0
477+
program = ["/bin/bash", "${path.module}/scripts/install-binaries.sh", local.binaries_path]
472478
}
473479

474480
data "external" "es_metadata" {
475-
count = var.enable_kibana_dashboard ? 1 : 0
476-
program = ["bash", "${path.module}/scripts/es_metadata.sh"]
481+
depends_on = [data.external.install_required_binaries]
482+
count = var.enable_kibana_dashboard ? 1 : 0
483+
program = ["bash", "${path.module}/scripts/es_metadata.sh", local.binaries_path]
477484
query = {
478485
url = "https://${local.elasticsearch_hostname}:${local.elasticsearch_port}"
479486
username = local.elasticsearch_username

solutions/fully-configurable/scripts/es_metadata.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
set -euo pipefail
44

5+
# The binaries downloaded by the install-binaries script are located in the /tmp directory.
6+
export PATH=$PATH:${1:-"/tmp"}
7+
58
# Read JSON from stdin
69
INPUT_JSON="$(cat)"
710

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
# scripts placed in the root module when they are invoked individually.
4+
# Placing it here also avoids duplicating the install-binaries script across modules.
5+
6+
set -o errexit
7+
set -o pipefail
8+
9+
DIRECTORY=${1:-"/tmp"}
10+
export PATH=$PATH:$DIRECTORY
11+
# renovate: datasource=github-tags depName=terraform-ibm-modules/common-bash-library
12+
TAG=v0.4.0
13+
# Running multiple Terraform executions on the same environment that share a /tmp directory can lead to conflicts during script execution.
14+
TMP_DIR=$(mktemp -d "${DIRECTORY}/common-bash-XXXXX")
15+
16+
echo "Downloading common-bash-library version ${TAG}." >&2
17+
18+
# download common-bash-library
19+
curl --silent \
20+
--connect-timeout 5 \
21+
--max-time 10 \
22+
--retry 3 \
23+
--retry-delay 2 \
24+
--retry-connrefused \
25+
--fail \
26+
--show-error \
27+
--location \
28+
--output "${TMP_DIR}/common-bash.tar.gz" \
29+
"https://github.com/terraform-ibm-modules/common-bash-library/archive/refs/tags/$TAG.tar.gz"
30+
31+
mkdir -p "${TMP_DIR}/common-bash-library"
32+
tar -xzf "${TMP_DIR}/common-bash.tar.gz" -C "${TMP_DIR}"
33+
rm -f "${TMP_DIR}/common-bash.tar.gz"
34+
35+
# The file doesn’t exist at the time shellcheck runs, so this check is skipped.
36+
# shellcheck disable=SC1091,SC1090
37+
source "${TMP_DIR}/common-bash-library-${TAG#v}/common/common.sh"
38+
39+
echo "Installing jq." >&2
40+
install_jq "latest" "${DIRECTORY}" "true"
41+
42+
rm -rf "$TMP_DIR"
43+
44+
echo "Installation complete successfully" >&2
45+
46+
# Output JSON for Terraform external data source
47+
echo '{"status":"success"}'

solutions/fully-configurable/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,3 +705,10 @@ variable "cbr_code_engine_kibana_project_rules" {
705705
description = "(Optional, list) List of context-based restrictions rules to create for the Kibana dashboard and it is only applicable if `enable_kibana_dashboard` is true. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-icd-elasticsearch/tree/main/solutions/standard/DA-cbr_rules.md)"
706706
default = []
707707
}
708+
709+
variable "install_required_binaries" {
710+
type = bool
711+
default = true
712+
description = "When set to true, a script will run to check if `jq` exist on the runtime and if not attempt to download it from the public internet and install it to /tmp. Set to false to skip running this script."
713+
nullable = false
714+
}

tests/pr_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ func TestRunSecurityEnforcedUpgradeSolution(t *testing.T) {
298298
TarIncludePatterns: []string{
299299
"*.tf",
300300
fullyConfigurableSolutionTerraformDir + "/*.tf",
301+
fullyConfigurableSolutionTerraformDir + "/scripts/*.sh",
301302
securityEnforcedSolutionTerraformDir + "/*.tf",
302303
},
303304
TemplateFolder: securityEnforcedSolutionTerraformDir,

0 commit comments

Comments
 (0)