From 75c79fecd82aa0281213379ad4604662e3568445 Mon Sep 17 00:00:00 2001 From: Dustin Kaiser Date: Fri, 3 Jan 2025 09:44:24 +0100 Subject: [PATCH] Add files remove typo --- services/monitoring/grafana/terraform/.gitignore | 2 +- .../tf_helper_list_json_files_in_folder.sh | 16 ++++++++++++++++ .../terraform/tf_helper_list_subfolders.sh | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100755 services/monitoring/grafana/terraform/tf_helper_list_json_files_in_folder.sh create mode 100755 services/monitoring/grafana/terraform/tf_helper_list_subfolders.sh diff --git a/services/monitoring/grafana/terraform/.gitignore b/services/monitoring/grafana/terraform/.gitignore index c21f5264..a99c01d2 100644 --- a/services/monitoring/grafana/terraform/.gitignore +++ b/services/monitoring/grafana/terraform/.gitignore @@ -1,5 +1,5 @@ main.tf -.terraform/** */ +.terraform/** .terraform.lock.hcl plan.cache terraform.tfstate diff --git a/services/monitoring/grafana/terraform/tf_helper_list_json_files_in_folder.sh b/services/monitoring/grafana/terraform/tf_helper_list_json_files_in_folder.sh new file mode 100755 index 00000000..65f0267b --- /dev/null +++ b/services/monitoring/grafana/terraform/tf_helper_list_json_files_in_folder.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -e + +DIRECTORY=$1 + +# Find all JSON files within the directory +FILES=$(find "$DIRECTORY" -mindepth 1 -maxdepth 1 -type f -name '*.json') + +# Create a JSON object where each file's basename is the key, with full paths as values +JSON_OBJECT=$(echo "$FILES" | while read -r FILE; do + BASENAME=$(basename "$FILE" .json) + echo "{\"$BASENAME\": \"$FILE\"}" +done | jq -s 'add') + +# Output the JSON map +jq -n --argjson files "$JSON_OBJECT" '$files' diff --git a/services/monitoring/grafana/terraform/tf_helper_list_subfolders.sh b/services/monitoring/grafana/terraform/tf_helper_list_subfolders.sh new file mode 100755 index 00000000..2b61270a --- /dev/null +++ b/services/monitoring/grafana/terraform/tf_helper_list_subfolders.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -e + +DIRECTORY=$1 + +# Use `find` to get the directories' base names +SUBFOLDERS=$(find "$DIRECTORY" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) + +# Convert the subfolder names into a JSON object with jq, where each is paired with itself +JSON_OBJECT=$(echo "$SUBFOLDERS" | tr ' ' '\n' | jq -Rn ' + [inputs] | + map(select(. != "")) | + map({key: ., value: .}) | + from_entries') +# Output the JSON map +jq -n --argjson subfolders "$JSON_OBJECT" '$subfolders'