Skip to content

Commit

Permalink
Add files remove typo
Browse files Browse the repository at this point in the history
  • Loading branch information
mrnicegyu11 committed Jan 3, 2025
1 parent 989eaa3 commit 75c79fe
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion services/monitoring/grafana/terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main.tf
.terraform/** */
.terraform/**
.terraform.lock.hcl
plan.cache
terraform.tfstate
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
16 changes: 16 additions & 0 deletions services/monitoring/grafana/terraform/tf_helper_list_subfolders.sh
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit 75c79fe

Please sign in to comment.