mykiwi/mykiwi.blogpublic Fork 0
9349201
Commits
Clone
git clone https://git.rickub.com/mykiwi/mykiwi.blog.git
git clone ssh://git@rickub.com/mykiwi/mykiwi.blog.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Derive Makefile and Terraform language sets from one file

LANGS in the Makefile and locals.languages in infra/main.tf were two
independently hand-maintained copies of the same five-language list,
with blog/hugo.toml's [languages.*] blocks as an unlinked third. Add
languages.txt as the shared source for the two that can read it -
OpenTofu has no TOML parser, so hugo.toml still has to be kept in sync
by hand, but that's now one drift point instead of two.
Romain Gautier committed 2026-09-18T22:14:05+02:00 Browse files
9349201 parent: 39fe402
modified Makefile +5 -1
@@ -7,7 +7,11 @@ include .env
77 export
88 endif
99
10-LANGS := en fr pt ja es
10+# languages.txt is the single source of truth for the site's language set,
11+# shared with infra/main.tf - blog/hugo.toml's [languages.*] blocks are the
12+# one place it can't drive directly (Tofu has no TOML parser), so keep those
13+# in sync by hand.
14+LANGS := $(shell cat languages.txt)
1115
1216 # deploy-% targets aren't listed here: giving an instantiated pattern target
1317 # (e.g. deploy-en) to .PHONY creates an explicit no-recipe rule for it, which
@@ -7,7 +7,11 @@ include .env
7 export7 export
8 endif8 endif
9 9
10-LANGS := en fr pt ja es10+# languages.txt is the single source of truth for the site's language set,
11+# shared with infra/main.tf - blog/hugo.toml's [languages.*] blocks are the
12+# one place it can't drive directly (Tofu has no TOML parser), so keep those
13+# in sync by hand.
14+LANGS := $(shell cat languages.txt)
11 15
12 # deploy-% targets aren't listed here: giving an instantiated pattern target16 # deploy-% targets aren't listed here: giving an instantiated pattern target
13 # (e.g. deploy-en) to .PHONY creates an explicit no-recipe rule for it, which17 # (e.g. deploy-en) to .PHONY creates an explicit no-recipe rule for it, which
modified infra/main.tf +10 -5
@@ -2,13 +2,18 @@
22 # matching blog/hugo.toml's multihost [languages.*] baseURLs: each language
33 # is a fully separate site (public/<lang>/ from the Hugo build) deployed to
44 # its own subdomain, with English at the zone apex.
5+#
6+# The language codes themselves come from ../languages.txt, the same file
7+# the Makefile reads for its deploy fan-out, so the two never drift apart.
8+# blog/hugo.toml's [languages.*] blocks can't read that file too (Tofu has
9+# no TOML parser to return the favor) - keep that one in sync by hand.
510 locals {
11+ language_codes = split(" ", trimspace(file("${path.module}/../languages.txt")))
612 languages = {
7- en = { hostname = var.zone_name, project_name = "mykiwi-blog-en" }
8- fr = { hostname = "fr.${var.zone_name}", project_name = "mykiwi-blog-fr" }
9- pt = { hostname = "pt.${var.zone_name}", project_name = "mykiwi-blog-pt" }
10- ja = { hostname = "ja.${var.zone_name}", project_name = "mykiwi-blog-ja" }
11- es = { hostname = "es.${var.zone_name}", project_name = "mykiwi-blog-es" }
13+ for code in local.language_codes : code => {
14+ hostname = code == "en" ? var.zone_name : "${code}.${var.zone_name}"
15+ project_name = "mykiwi-blog-${code}"
16+ }
1217 }
1318 }
1419
@@ -2,13 +2,18 @@
2 # matching blog/hugo.toml's multihost [languages.*] baseURLs: each language2 # matching blog/hugo.toml's multihost [languages.*] baseURLs: each language
3 # is a fully separate site (public/<lang>/ from the Hugo build) deployed to3 # is a fully separate site (public/<lang>/ from the Hugo build) deployed to
4 # its own subdomain, with English at the zone apex.4 # its own subdomain, with English at the zone apex.
5+#
6+# The language codes themselves come from ../languages.txt, the same file
7+# the Makefile reads for its deploy fan-out, so the two never drift apart.
8+# blog/hugo.toml's [languages.*] blocks can't read that file too (Tofu has
9+# no TOML parser to return the favor) - keep that one in sync by hand.
5 locals {10 locals {
11+ language_codes = split(" ", trimspace(file("${path.module}/../languages.txt")))
6 languages = {12 languages = {
7- en = { hostname = var.zone_name, project_name = "mykiwi-blog-en" }13+ for code in local.language_codes : code => {
8- fr = { hostname = "fr.${var.zone_name}", project_name = "mykiwi-blog-fr" }14+ hostname = code == "en" ? var.zone_name : "${code}.${var.zone_name}"
9- pt = { hostname = "pt.${var.zone_name}", project_name = "mykiwi-blog-pt" }15+ project_name = "mykiwi-blog-${code}"
10- ja = { hostname = "ja.${var.zone_name}", project_name = "mykiwi-blog-ja" }16+ }
11- es = { hostname = "es.${var.zone_name}", project_name = "mykiwi-blog-es" }
12 }17 }
13 }18 }
14 19
added languages.txt +1 -0
new file mode 100644
@@ -0,0 +1 @@
1+en fr pt ja es
new file mode 100644
@@ -0,0 +1 @@
1+en fr pt ja es