-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Add: Manage grafana content/assets via terraform #913
base: main
Are you sure you want to change the base?
Changes from all commits
f0d8cf0
e906b41
14c751d
293f63c
f7f72ec
94cfb76
509c717
1a65ecf
77ee45e
c9c70d6
7b8be53
bcd61cd
58e1030
5b1c3fb
00bc0c7
2e009bc
8903007
f520e7c
764bb22
ead277a
13f92ba
ebe66c0
fcab094
2ba8070
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -22,6 +22,13 @@ $(if $(REPO_CONFIG_LOCATION),,$(error The location of the repo.config file given | |||||
$(if $(shell cat $(REPO_CONFIG_LOCATION)),,$(error The location of the repo.config file given in .config.location is invalid. Aborting)) | ||||||
$(if $(shell wc -l $(REPO_BASE_DIR)/.config.location | grep 1),,$(error The .config.location file has more than one path specified. Only one path is allowed. Aborting)) | ||||||
|
||||||
# Extract DEPLOYMENT_FQDN using Make functions | ||||||
DEPLOYMENT_FQDN := $(notdir $(patsubst %/,%, $(dir $(REPO_CONFIG_LOCATION)))) | ||||||
# Construct CI_ENV_FILE using Make functions | ||||||
CI_ENV_FILE := $(realpath $(dir $(REPO_CONFIG_LOCATION))/../../.gitlab/pipelines/1_configurations/$(DEPLOYMENT_FQDN)/ci.env) | ||||||
$(if $(CI_ENV_FILE),,$(error The location of the repo.config file given in .config.location is invalid. Cannot find the ci.env file. Aborting)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not going to work in CI where we do not have |
||||||
$(if $(shell cat $(CI_ENV_FILE)),,$(error The location of the repo.config file given in .config.location is invalid. Cannot find the ci.env file. Aborting)) | ||||||
|
||||||
ifeq ($(_yq),) | ||||||
_yq = docker run --rm -i -v $${PWD}:/workdir mikefarah/yq:4.30.4 | ||||||
endif | ||||||
|
@@ -253,13 +260,13 @@ venv: $(REPO_BASE_DIR)/.venv/bin/activate ## Creates a python virtual environmen | |||||
ifeq ($(shell test -f j2cli_customization.py && echo -n yes),yes) | ||||||
|
||||||
define jinja | ||||||
$(REPO_BASE_DIR)/.venv/bin/j2 --format=env $(1) .env -o $(2) --customize j2cli_customization.py | ||||||
$(REPO_BASE_DIR)/.venv/bin/j2 --format=env $(1) $(2) -o $(3) --customize j2cli_customization.py | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure if for a single corner case we need to repeat Ideas:
Suggested change
|
||||||
endef | ||||||
|
||||||
else | ||||||
|
||||||
define jinja | ||||||
$(REPO_BASE_DIR)/.venv/bin/j2 --format=env $(1) .env -o $(2) | ||||||
$(REPO_BASE_DIR)/.venv/bin/j2 --format=env $(1) $(2) -o $(3) | ||||||
endef | ||||||
|
||||||
endif | ||||||
|
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' |
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 was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
.DEFAULT_GOAL := help | ||
REPO_BASE_DIR := $(shell git rev-parse --show-toplevel) | ||
include ${REPO_BASE_DIR}/scripts/common.Makefile | ||
|
||
|
||
|
||
# Internal VARIABLES ------------------------------------------------ | ||
TF_STATE_FILE := terraform/.terraform/terraform.tfstate | ||
|
||
terraform/main.tf: terraform/main.tf.j2 .venv $(CI_ENV_FILE) | ||
# generate $@ | ||
@$(call jinja, $<, $(CI_ENV_FILE), $@) | ||
# validate and format $@ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it a redundant line? |
||
|
||
terraform-init: $(TF_STATE_FILE) ## init terraform | ||
|
||
$(TF_STATE_FILE): $(CI_ENV_FILE) terraform/main.tf | ||
# terraform init | ||
@set -a; source $<; set +a; \ | ||
if [ "$${TF_STATE_BACKEND_TYPE}" = "local" ]; then \ | ||
terraform -chdir=./terraform init; \ | ||
else \ | ||
terraform -chdir=./terraform init -backend-config="access_key=$${TF_BACKEND_ACCESS_KEY}" -backend-config="secret_key=$${TF_BACKEND_SECRET_KEY}"; \ | ||
fi | ||
|
||
terraform/plan.cache: | ||
@echo "$@ file not found. Run 'make terraform-plan' to generate it." | ||
@exit 1 | ||
|
||
.PHONY: terraform-plan | ||
terraform-plan: $(CI_ENV_FILE) $(TF_STATE_FILE) ensure-grafana-online ## terraform plan | ||
# terraform plan | ||
@set -a; source $<; source $${REPO_CONFIG_LOCATION}; set +a; \ | ||
TF_VAR_aws_region=$${TF_AWS_REGION} TF_VAR_aws_access_key=$${TF_AWS_ACCESS_KEY_ID} TF_VAR_aws_secret_key=$${TF_AWS_SECRET_ACCESS_KEY} terraform -chdir=./terraform plan -out=plan.cache | ||
|
||
.PHONY: terraform-apply | ||
terraform-apply: $(CI_ENV_FILE) terraform/plan.cache $(TF_STATE_FILE) ensure-grafana-online ## terraform apply | ||
# terraform apply | ||
@set -a; source $<; set +a; \ | ||
TF_VAR_aws_region=$${TF_AWS_REGION} TF_VAR_aws_access_key=$${TF_AWS_ACCESS_KEY_ID} TF_VAR_aws_secret_key=$${TF_AWS_SECRET_ACCESS_KEY} terraform -chdir=./terraform apply plan.cache | ||
|
||
.PHONY: ensure-grafana-online | ||
ensure-grafana-online: | ||
@set -o allexport; \ | ||
source $(REPO_CONFIG_LOCATION); \ | ||
set +o allexport; \ | ||
url=$${TF_VAR_GRAFANA_URL}; \ | ||
echo "Waiting for grafana at $$url to become reachable..."; \ | ||
while true; do \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we add a timeout here to avoid waiting forever? |
||
status_code=$$(curl -k -o /dev/null -s -w "%{http_code}" $$url); \ | ||
if [ "$$status_code" -ge 200 ] && [ "$$status_code" -lt 400 ]; then \ | ||
echo "Grafana is online"; \ | ||
break; \ | ||
else \ | ||
echo "Grafana still unreachable, waiting 5s for grafana to become reachable..."; \ | ||
sleep 5; \ | ||
fi; \ | ||
done; |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if hardcoding assumptions about the other repo here is sustainable.
We can brainstorm together what can be done and if we can avoid using
ci.env
file here