From 3335482efce346da0e720de87914d52d4ade0588 Mon Sep 17 00:00:00 2001 From: Noel Sabia Date: Tue, 27 Oct 2026 14:29:59 +0100 Subject: [PATCH] chore(terraform): pin cloudflare and hcloud providers, add build plan --- terraform/.gitignore | 1 - terraform/.terraform.lock.hcl | 40 ++++++++++ terraform/plan.md | 135 ++++++++++++++++++++++++++++++++++ terraform/versions.tf | 28 +++---- 4 files changed, 187 insertions(+), 17 deletions(-) create mode 100644 terraform/.terraform.lock.hcl create mode 100644 terraform/plan.md diff --git a/terraform/.gitignore b/terraform/.gitignore index 6bc0c55..d7822b3 100644 --- a/terraform/.gitignore +++ b/terraform/.gitignore @@ -5,6 +5,5 @@ *.tfvars !terraform.tfvars.example .terraform/ -.terraform.lock.hcl kubeconfig crash.log diff --git a/terraform/.terraform.lock.hcl b/terraform/.terraform.lock.hcl new file mode 100644 index 0000000..910e934 --- /dev/null +++ b/terraform/.terraform.lock.hcl @@ -0,0 +1,40 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/cloudflare/cloudflare" { + version = "5.28.1" + constraints = "5.28.1" + hashes = [ + "h1:9YL6g+iEfg3OzX6qSZOYsictVO0fNP09D6jRwIZKwQ0=", + "zh:219d464dd727c0e5c90a97b44aa5d7988acc4eec47f3684f7ecd006b17c46d9c", + "zh:2511f2380209c81121e6eb943d7e68d03602a4fcf4f0311dfc67e198179b9303", + "zh:2ae200482bf592cd703981c4d4fe87a52c0dfae81a70261295f59b1bb0d01a6c", + "zh:7df6fe6573379c2faf2e801fdbca58ac909266dbee604feaa993439b8616c9b3", + "zh:9fb5a295588351ce565515dc2a770047e8bab786a4a9665511ab9a9ca2db5f1b", + "zh:a182f4aec86c74e9db4affa22323c5a21f5d92c1fcf91b934570753d04f4daf8", + "zh:a39bb8624fb6c714e38bc0e632aae117a9fede5a18a248ab15dd1b60013c0324", + "zh:bef2ffbdb68569549fe432b550592e07456759a7288f84f7c37c9d933a493f54", + "zh:f809ab383cca0a5f83072981c64208cbd7fa67e986a86ee02dd2c82333221e32", + ] +} + +provider "registry.terraform.io/hetznercloud/hcloud" { + version = "1.70.2" + constraints = "1.70.2" + hashes = [ + "h1:BZWdJOileBlR+WMz0D0wrJXFhNLJpHcQJIgDqmPNlpw=", + "zh:05a474ecd2b019be03f857877c9bf1eca8f96c0897f6e76b91780adf3a8dd388", + "zh:1d4e4c0525c02618c015c079dc3e8d8b693ca796d698f95b59c4412114cbf166", + "zh:1f3bc703423f08a295e3e8f6d39c3f155e672da5e20b9a143ef7e7a465be37e3", + "zh:20ced3eec332b587a998ad3d87da322736aef49cb7e561a545a57f9a08000050", + "zh:619152b472b9ac266046db9d0c3f85946559ce0791bcb6fc78d278bb555d4572", + "zh:658a84427cc6b5385d68e1506678498dd7d3d04c0cf3410e3f2278c05b247ade", + "zh:6d9be3d79479345d21cef66e83002086153189535c82ab299d6ca5021aec7d0e", + "zh:72b0d26aadcc422ccb17e7a89abf92dfbe52dca6fc80025a934d7c4e058888cd", + "zh:865c0dc4912a5009f7b8c7ff374d47e496f9cfe96cbcebadc48f3434b7c12b46", + "zh:99f3f0778398d7348e5ab7dab42de0c918339a5250d140b6959272e50be4e372", + "zh:b3df6415bbe0f7021f94bff9e640c42e6d45b4a459ded3d267f10e2104a77760", + "zh:e7645b34e1aa45cb17dc473b33d7fa4d60e81d7e14332c7b04bc97535c867074", + "zh:f60b3e67be5cafe10001bb556ae7693e4a7696fb6946294643182946b36117f9", + ] +} diff --git a/terraform/plan.md b/terraform/plan.md new file mode 100644 index 0000000..50d8f47 --- /dev/null +++ b/terraform/plan.md @@ -0,0 +1,135 @@ +# Build plan + +Working order for `terraform/`. Each step ends in something verifiable; do not +start the next one until the check passes. + +Goal: `terraform apply` + `kubectl apply -k deploy/` rebuilds the whole system +on an empty machine. See `OKF_CV_Website/architecture/terraform.md`. + +## Open decisions + +- [X] **Where does the server come from?** Proxmox VM on the home server, or a + cloud VM. Sets the provider, the key mechanism, and whether `server_host` + is known before `apply` or produced by it. -> Server comes from Hetzner +- [X] **Does Terraform create the VM, or only bootstrap it?** Creating it makes + `server_host` an output instead of an input. -> creates a server at hetzner not a vm (yes i know they will use a virtualizer but you understand) +- [X] **Provisioning mechanism:** `remote-exec` over SSH, or provider + `user_data`/cloud-init. cloud-init is idempotent at boot and needs no SSH; + provisioners are what `variables.tf` is currently shaped for. Pick one + before writing `main.tf`. -> depends i don't know the tradeoffs + +## Steps + +### 1. Server source + +Decide the two open questions above. Write them into this file so later steps +have a fixed target. + +Check: one sentence answers "what does `apply` create?". + +### 2. SSH key — done + +`~/.ssh/cv_infra` and `~/.ssh/cv_infra.pub` exist. The public half goes onto the +server during creation (step 6), not after. + +Check: `ssh-keygen -y -f ~/.ssh/cv_infra` prints the public key. + +### 3. Provider and versions + +Uncomment `versions.tf`, set `required_version` and the provider(s), run +`terraform init`. Commit `.terraform.lock.hcl` is currently ignored — decide +whether that stays. + +Check: `terraform init` succeeds, `.terraform.lock.hcl` exists. + +### 4. Inputs + +Copy `terraform.tfvars.example` to `terraform.tfvars`, fill `server_host`, +`domain`, `cloudflare_zone_id`, and set +`ssh_private_key_path = "~/.ssh/cv_infra"`. Export `CLOUDFLARE_API_TOKEN`. + +Check: `terraform validate` passes. + +### 5. DNS first + +Write `dns.tf`: one `cloudflare_record` for the apex A record. Smallest real +resource, and it exercises provider, token and zone ID with no server involved. + +Check: `terraform apply` creates the record, `dig +short ` returns the +server IP. + +### 6. Server creation + +Add the server resource with the SSH public key attached at creation. + +Check: `terraform apply` creates it, `ssh -i ~/.ssh/cv_infra @` +works without a password. + +### 7. Connection skeleton + +One `null_resource` with a `connection` block that runs `uname -a`. Sort out +host key handling here (`host_key` pinned vs. `insecure_ignore_host_key`) and +the wait-for-port-22 problem. + +Check: `terraform apply` returns the remote `uname -a` output. + +### 8. Base system + +Packages, 2 GB swapfile, containerd, then kubeadm/kubelet/kubectl. Every command +must be safe to re-run — provisioners have no state tracking. + +Check: `swapfile` active, `containerd` and `kubelet` enabled, `kubeadm version` +matches the design. + +### 9. Control plane + +`kubeadm init` with `--pod-network-cidr` for Calico, then install the kubeconfig +on the local machine (never in Git). + +Check: `kubectl get nodes` shows the control plane `Ready` once Calico is in. + +### 10. Addons + +Calico, metrics-server, local-path provisioner — bootstrap only, never +reconciled after this. + +Check: `kubectl top nodes` returns data, a test PVC binds. + +### 11. Caddy + +Install Caddy, template the Caddyfile with `reverse_proxy 127.0.0.1:8080`. DNS +record must be DNS-only at Cloudflare (grey cloud) or ACME fails. + +Check: `curl -I https://` returns a valid certificate; 502 is fine at +this point because nothing is listening yet. + +### 12. Outputs + +Add the kubeconfig path next to the placeholder in `outputs.tf:13-14`. + +Check: `terraform output` shows `server_ip`, `proxy_url`, kubeconfig path. + +### 13. Workloads in `deploy/` + +Namespace `cv`, quota, gateway Service on NodePort 8080, then the site +workloads. Applied with `kubectl apply -k deploy/`, not Terraform. + +Check: site loads over HTTPS. + +### 14. Acceptance test + +```sh +terraform destroy && terraform apply +kubectl apply -k deploy/ +``` + +Check: site back up from nothing, no manual steps in between. This is the only +test that matters; everything above is scaffolding for it. + +## Notes + +- State is local and Git-ignored on purpose; a lost state file means rebuild. +- Terraform manages nothing inside the cluster beyond bootstrap. +- A partial `remote-exec` failure leaves a half-configured server and a state + file that thinks it succeeded. When step 8 misbehaves, `terraform taint` is + the escape hatch. diff --git a/terraform/versions.tf b/terraform/versions.tf index 25f6c56..4c8a011 100644 --- a/terraform/versions.tf +++ b/terraform/versions.tf @@ -1,17 +1,13 @@ -# Provider requirements. +terraform { + required_providers { + cloudflare = { + source = "cloudflare/cloudflare" + version = "5.28.1" + } + hcloud = { + source = "hetznercloud/hcloud" + version = "1.70.2" + } + } +} -# Set once the providers are chosen and versions verified with `terraform init`. -# DNS lives at Cloudflare, so that provider is expected here. -# terraform { -# required_version = ">= 1.9" -# required_providers { -# cloudflare = { -# source = "cloudflare/cloudflare" -# version = "~> x.y" -# } -# null = { -# source = "hashicorp/null" -# version = "~> 3.2" -# } -# } -# }