Skip to content

Commit c2c748f

Browse files
committed
Rename and refactor
1 parent c52b3f9 commit c2c748f

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

scripts/common.Makefile

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,6 @@ $(if $(shell wc -l $(REPO_BASE_DIR)/.config.location | grep 1),,$(error The .con
2424

2525
# Extract DEPLOYMENT_FQDN using Make functions
2626
DEPLOYMENT_FQDN := $(notdir $(patsubst %/,%, $(dir $(REPO_CONFIG_LOCATION))))
27-
# Construct CI_ENV_FILE using Make functions
28-
CI_ENV_FILE := $(realpath $(dir $(REPO_CONFIG_LOCATION))/../../.gitlab/pipelines/1_configurations/$(DEPLOYMENT_FQDN)/ci.env)
29-
# Check if ci.env exists and is not empty
30-
ifeq ($(shell [ -e $(CI_ENV_FILE) ] && cat $(CI_ENV_FILE)),)
31-
# If ci.env does not exist, check for ansible.env
32-
ANSIBLE_ENV_FILE := $(REPO_CONFIG_LOCATION)/ansible.env
33-
ifeq ($(shell [ -e $(ANSIBLE_ENV_FILE) ] && cat $(ANSIBLE_ENV_FILE)),)
34-
$(error Neither the ci.env file nor the ansible.env file could be found. Aborting.)
35-
else
36-
$(warning ci.env file is missing. Falling back to ansible.env file. We assume that you are running in a CI pipeline.)
37-
CI_ENV_FILE := $(ANSIBLE_ENV_FILE)
38-
endif
39-
endif
40-
4127
# Use SELECTED_ENV_FILE in your targets as needed
4228
ifeq ($(_yq),)
4329
_yq = docker run --rm -i -v $${PWD}:/workdir mikefarah/yq:4.30.4

services/monitoring/grafana/Makefile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,37 @@ include ${REPO_BASE_DIR}/scripts/common.Makefile
77
# Internal VARIABLES ------------------------------------------------
88
TF_STATE_FILE := terraform/.terraform/terraform.tfstate
99

10-
terraform/main.tf: terraform/main.tf.j2 .venv $(CI_ENV_FILE)
10+
terraform/main.tf: terraform/main.tf.j2 .venv $(REPO_CONFIG_LOCATION)
1111
# generate $@
12-
@$(call jinja, $<, $(CI_ENV_FILE), $@)
12+
@$(call jinja, $<, $(REPO_CONFIG_LOCATION), $@)
1313
# validate and format $@
1414

1515
terraform-init: $(TF_STATE_FILE) ## init terraform
1616

17-
$(TF_STATE_FILE): $(CI_ENV_FILE) terraform/main.tf
17+
$(TF_STATE_FILE): $(REPO_CONFIG_LOCATION) terraform/main.tf
1818
# terraform init
1919
@set -a; source $<; set +a; \
20-
if [ "$${TF_STATE_BACKEND_TYPE}" = "local" ]; then \
20+
if [ "$${GRAFANA_TERRAFORM_STATE_BACKEND_TYPE}" = "local" ]; then \
2121
terraform -chdir=./terraform init; \
2222
else \
23-
terraform -chdir=./terraform init -backend-config="access_key=$${TF_BACKEND_ACCESS_KEY}" -backend-config="secret_key=$${TF_BACKEND_SECRET_KEY}"; \
23+
terraform -chdir=./terraform init -backend-config="access_key=$${GRAFANA_TERRAFORM_STATE_BACKEND_AWS_ACCESS_KEY_ID}" -backend-config="secret_key=$${GRAFANA_TERRAFORM_STATE_BACKEND_AWS_SECRET_ACCESS_KEY}"; \
2424
fi
2525

2626
terraform/plan.cache:
2727
@echo "$@ file not found. Run 'make terraform-plan' to generate it."
2828
@exit 1
2929

3030
.PHONY: terraform-plan
31-
terraform-plan: $(CI_ENV_FILE) $(TF_STATE_FILE) ensure-grafana-online ## terraform plan
31+
terraform-plan: $(REPO_CONFIG_LOCATION) $(TF_STATE_FILE) ensure-grafana-online ## terraform plan
3232
# terraform plan
33-
@set -a; source $<; source $${REPO_CONFIG_LOCATION}; set +a; \
34-
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
33+
@set -a; source $<; set +a; \
34+
terraform -chdir=./terraform plan -out=plan.cache
3535

3636
.PHONY: terraform-apply
37-
terraform-apply: $(CI_ENV_FILE) terraform/plan.cache $(TF_STATE_FILE) ensure-grafana-online ## terraform apply
37+
terraform-apply: $(REPO_CONFIG_LOCATION) terraform/plan.cache $(TF_STATE_FILE) ensure-grafana-online ## terraform apply
3838
# terraform apply
3939
@set -a; source $<; set +a; \
40-
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
40+
terraform -chdir=./terraform apply plan.cache
4141

4242
.PHONY: ensure-grafana-online
4343
ensure-grafana-online:

services/monitoring/grafana/terraform/main.tf.j2

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
terraform {
2-
required_version = "~> 1.5.1"
3-
{% if TF_STATE_BACKEND_TYPE == "local" %}
4-
backend "{{TF_STATE_BACKEND_TYPE}}" {
2+
required_version = "~> 1.10.1"
3+
{% if GRAFANA_TERRAFORM_STATE_BACKEND_TYPE == "local" %}
4+
backend "{{ GRAFANA_TERRAFORM_STATE_BACKEND_TYPE }}" {
55
path = "terraform.tfstate" # Specify the path for the state file, can be a different path if needed
66
}
77
{% endif %}
8-
{% if TF_STATE_BACKEND_TYPE == "s3" %}
8+
{% if GRAFANA_TERRAFORM_STATE_BACKEND_TYPE == "s3" %}
99
backend "s3" {
10-
key = "{{ TF_STATE_S3_GRAFANAKEY}}"
11-
dynamodb_table = "{{ TF_STATE_S3_DYNAMODB_LOCK_TABLE }}"
12-
encrypt = true
10+
key = "{{ GRAFANA_TERRAFORM_STATE_BACKEND_S3_KEY }}"
11+
use_lockfile = true
12+
encrypt = false
1313
bucket = "{{ TF_STATE_S3_BUCKET_NAME }}"
1414
region = "{{ TF_STATE_S3_REGION }}"
15+
{% if GRAFANA_TERRAFORM_STATE_BACKEND_S3_ENDPOINT %}
16+
endpoints = {
17+
s3 = "{{ GRAFANA_TERRAFORM_STATE_BACKEND_S3_ENDPOINT }}"
18+
}
19+
{% endif %}
1520
}
1621
{% endif %}
1722
required_providers {

0 commit comments

Comments
 (0)