SHELL := /bin/bash

include .env
export

DNS_OUTPUT = "dns/hosts.js"
SERVICES_OUTPUT = "services/inventory/group_vars/all/opentofu.yaml"

$(DNS_OUTPUT):
	cd opentofu && \
		tofu output --json \
		| jq 'with_entries(.value |= .value).hosts' \
		> ../dns/hosts.json

$(SERVICES_OUTPUT):
	cd opentofu && \
		tofu output --json \
		| yq -y '{opentofu: with_entries(.value |= .value)}' \
		> ../services/inventory/group_vars/all/opentofu.yaml

outputs: $(DNS_OUTPUT) $(SERVICES_OUTPUT)


./types-dnscontrol.d.ts:
	dnscontrol write-types

dns: $(DNS_OUTPUT) ./types-dnscontrol.d.ts
	dnscontrol push

dns-check: $(DNS_OUTPUT) ./types-dnscontrol.d.ts
	dnscontrol check-creds ovh