| Add Cloudflare provisioning and deploy tooling e4c5d34 Romain Gautier 18h ago | 1 | # One Cloudflare Pages project + custom domain + DNS record per language, |
| 2 | # matching blog/hugo.toml's multihost [languages.*] baseURLs: each language |
| 3 | # is a fully separate site (public/<lang>/ from the Hugo build) deployed to |
| 4 | # its own subdomain, with English at the zone apex. |
| 5 | locals { |
| 6 | 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" } |
| Add Spanish (es) language support 479f7e2 Romain Gautier 14h ago | 11 | es = { hostname = "es.${var.zone_name}", project_name = "mykiwi-blog-es" } |
| Add Cloudflare provisioning and deploy tooling e4c5d34 Romain Gautier 18h ago | 12 | } |
| 13 | } |
| 14 | |
| 15 | data "cloudflare_zone" "this" { |
| 16 | name = var.zone_name |
| 17 | } |
| 18 | |
| 19 | # Direct-upload projects (no `source` block, i.e. no git integration) - |
| 20 | # deploys happen out-of-band, e.g. `wrangler pages deploy public/en |
| 21 | # --project-name=mykiwi-blog-en` from CI, since this repo lives on |
| 22 | # tangled.sh rather than GitHub. |
| 23 | resource "cloudflare_pages_project" "site" { |
| 24 | for_each = local.languages |
| 25 | |
| 26 | account_id = var.cloudflare_account_id |
| 27 | name = each.value.project_name |
| 28 | production_branch = "main" |
| 29 | } |
| 30 | |
| 31 | resource "cloudflare_pages_domain" "site" { |
| 32 | for_each = local.languages |
| 33 | |
| 34 | account_id = var.cloudflare_account_id |
| 35 | project_name = cloudflare_pages_project.site[each.key].name |
| 36 | domain = each.value.hostname |
| 37 | } |
| 38 | |
| 39 | resource "cloudflare_record" "site" { |
| 40 | for_each = local.languages |
| 41 | |
| 42 | zone_id = data.cloudflare_zone.this.id |
| 43 | name = each.key == "en" ? "@" : each.key |
| 44 | type = "CNAME" |
| 45 | content = cloudflare_pages_project.site[each.key].subdomain |
| 46 | proxied = true |
| 47 | } |
| 48 | |
| 49 | # www.mykiwi.blog -> mykiwi.blog (English apex), not its own language - just |
| 50 | # the one common typo/habit redirect, not a 5th site. |
| 51 | resource "cloudflare_record" "www" { |
| 52 | zone_id = data.cloudflare_zone.this.id |
| 53 | name = "www" |
| 54 | type = "CNAME" |
| 55 | content = var.zone_name |
| 56 | proxied = true |
| 57 | } |
| 58 | |
| 59 | resource "cloudflare_page_rule" "www_redirect" { |
| 60 | zone_id = data.cloudflare_zone.this.id |
| 61 | target = "www.${var.zone_name}/*" |
| 62 | priority = 1 |
| 63 | |
| 64 | actions { |
| 65 | forwarding_url { |
| 66 | url = "https://${var.zone_name}/$1" |
| 67 | status_code = 301 |
| 68 | } |
| 69 | } |
| 70 | } |