53 lines
2.8 KiB
Makefile
53 lines
2.8 KiB
Makefile
.DEFAULT_GOAL := help
|
|
|
|
.PHONY: install all help nixos infra-plan infra-apply infra-destroy infra-init-backends infra-init-all-backends
|
|
|
|
nixos-image: ## Build a new NixOS image (snapshot) on Hetzner Cloud. Check README.md to see how VERSION= and BUILD= should be set
|
|
@cd nixos; $(MAKE) $@
|
|
|
|
module-exists:
|
|
@test -z "$(MODULE)" && { printf "Please provide a module, e.g. MODULE=environment\n"; exit 1; }; \
|
|
test -d "infrastructure/$(MODULE)" || { printf "The module \"%s\" does not exist!\n" "$(MODULE)"; exit 1; }; \
|
|
|
|
infra-plan: ## Run `terraform plan` inside of infrastructure/$(MODULE), e.g. `make infra-plan MODULE=ingress`
|
|
@$(MAKE) module-exists MODULE="$(MODULE)" || exit 1; \
|
|
cd infrastructure/$(MODULE); \
|
|
terraform13.5 plan .
|
|
|
|
infra-apply: ## Run `terraform apply` inside of infrastructure/$(MODULE), e.g. `make infra-apply MODULE=ingress`
|
|
@$(MAKE) module-exists MODULE="$(MODULE)" || exit 1; \
|
|
cd infrastructure/$(MODULE); \
|
|
terraform13.5 apply .
|
|
|
|
infra-destroy: ## Run `terraform destroy` inside of infrastructure/$(MODULE), e.g. `make infra-destroy MODULE=ingress`
|
|
@$(MAKE) module-exists MODULE="$(MODULE)" || exit 1; \
|
|
cd infrastructure/$(MODULE); \
|
|
terraform13.5 destroy .
|
|
|
|
infra-init-backends: ## Initialize the backend of one or more modules, e.g. `make infra-init-backends MODULES="compute ingress"`
|
|
@get_value() { awk -v setting="$$1" -F"\"" '$$0 ~ setting {print $$4}' "$$2"; }; \
|
|
environment=$$(get_value "terraform_packer_environment" config.json); \
|
|
project=$$(get_value "terraform_gitlab_backend_project" secrets.json); \
|
|
username=$$(get_value "terraform_gitlab_backend_username" secrets.json); \
|
|
password=$$(get_value "terraform_gitlab_backend_password" secrets.json); \
|
|
cd infrastructure; \
|
|
for m in $(MODULES); do \
|
|
gitlab_address="https://gitlab.com/api/v4/projects/$$project/terraform/state/$$environment-$$m"; \
|
|
backend_params=""; \
|
|
backend_params="$$backend_params -backend-config=\"address=$$gitlab_address\""; \
|
|
backend_params="$$backend_params -backend-config=\"lock_address=$$gitlab_address/lock\""; \
|
|
backend_params="$$backend_params -backend-config=\"unlock_address=$$gitlab_address/lock\""; \
|
|
backend_params="$$backend_params -backend-config=\"username=$$username\""; \
|
|
backend_params="$$backend_params -backend-config=\"password=$$password\""; \
|
|
cd "$$m"; \
|
|
rm -rf .terraform; eval terraform13.5 init -reconfigure "$$backend_params" . ; \
|
|
cd ..; \
|
|
done; \
|
|
|
|
infra-init-all-backends: ## Initialize backends of all modules inside of the `infrastructure/` folder
|
|
@modules=$$(ls infrastructure/modules | xargs) && $(MAKE) infra-init-backends MODULES="$$modules"
|
|
|
|
all install help:
|
|
@printf "Available targets\n" && \
|
|
grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|