mykiwi/mykiwi.blogpublic Fork 0
a74fe0a29252e8de5b737ff5cf56888380055981
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.

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