-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58e1030
commit 5b1c3fb
Showing
8 changed files
with
161 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.5.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Import subfolders using an external script | ||
data "external" "subfolders" { | ||
program = ["bash", "${path.module}/../../../../scripts/tf_helper_list_subfolders.sh", "${path.module}/../assets/shared/dashboards"] | ||
} | ||
|
||
// Local mappings of folder names to their paths | ||
locals { | ||
folder_map = data.external.subfolders.result | ||
} | ||
|
||
// Create Grafana folders for each subfolder | ||
resource "grafana_folder" "subfolders" { | ||
for_each = local.folder_map | ||
|
||
title = each.key // Use each.key to access each folder's name | ||
} | ||
|
||
// Function to list all JSON files within a directory | ||
data "external" "dashboard_files" { | ||
for_each = local.folder_map | ||
|
||
program = ["bash", "${path.module}/../../../../scripts/tf_helper_list_json_files_in_folder.sh", "${path.module}/../assets/shared/dashboards/${each.key}"] | ||
} | ||
|
||
// Create Grafana dashboards from JSON files | ||
resource "grafana_dashboard" "dashboards" { | ||
for_each = toset(flatten([ | ||
for folder_name in keys(local.folder_map) : [ | ||
for file in values(data.external.dashboard_files[folder_name].result) : "${folder_name},${file}" | ||
]] | ||
)) | ||
# CSV approach | ||
config_json = jsonencode(jsondecode(file(split(",", each.value)[1])).dashboard) | ||
folder = grafana_folder.subfolders[split(",", each.value)[0]].id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
resource "grafana_data_source" "prometheusfederation" { | ||
type = "prometheus" | ||
name = "prometheus-federation" | ||
url = var.prometheus_federation_url | ||
basic_auth_enabled = false | ||
is_default = true | ||
} | ||
|
||
resource "grafana_data_source" "prometheuscatchall" { | ||
type = "prometheus" | ||
name = "prometheus-catchall" | ||
url = var.prometheus_catchall_url | ||
basic_auth_enabled = false | ||
is_default = false | ||
uid = "RmZEr52nz" | ||
} | ||
|
||
resource "grafana_data_source" "tempo" { | ||
type = "tempo" | ||
name = "tempo" | ||
url = var.tempo_url | ||
basic_auth_enabled = false | ||
is_default = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
terraform { | ||
required_version = "~> 1.5.1" | ||
backend "local" { | ||
path = "terraform.tfstate" # Specify the path for the state file, can be a different path if needed | ||
} | ||
required_providers { | ||
grafana = { | ||
source = "grafana/grafana" | ||
version = "~> 3.13" | ||
} | ||
random = { | ||
source = "hashicorp/random" | ||
version = "~> 3.1" | ||
} | ||
} | ||
} | ||
|
||
provider "grafana" { | ||
url = var.grafana_url | ||
auth = var.grafana_auth | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
variable "grafana_url" { | ||
description = "grafana_url" | ||
sensitive = false | ||
} | ||
variable "grafana_auth" { | ||
description = "Username:Password" | ||
sensitive = true | ||
} | ||
variable "prometheus_federation_url" { | ||
description = "Prometheus Federation URL" | ||
sensitive = false | ||
} | ||
variable "prometheus_catchall_url" { | ||
description = "Prometheus Catchall URL" | ||
sensitive = false | ||
} | ||
variable "tempo_url" { | ||
description = "Tempo URL" | ||
sensitive = false | ||
} |