SHELL := /bin/bash

include .env
export

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

$(DNS_OUTPUT):
	tofu output --json \
		| jq 'with_entries(.value |= .value).hosts' \
		> $(DNS_OUTPUT)

$(SERVICES_OUTPUT):
	tofu output --json \
		| yq -y '{opentofu: with_entries(.value |= .value)}' \
		> $(SERVICES_OUTPUT)

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