From f2493767bdb500d11a11a06620de0598804e79b0 Mon Sep 17 00:00:00 2001 From: Noel Sabia Date: Tue, 27 Oct 2026 12:12:08 +0100 Subject: [PATCH] chore(terraform): scaffold server provisioning layout Empty main.tf, dns.tf, variables.tf, outputs.tf and versions.tf matching OKF_CV_Website/architecture/terraform.md. Variables and outputs are written out; resources stay unwritten until the server facts are settled. --- terraform/.gitignore | 10 ++++++++++ terraform/README.md | 30 ++++++++++++++++++++++++++++++ terraform/dns.tf | 3 +++ terraform/main.tf | 6 ++++++ terraform/outputs.tf | 14 ++++++++++++++ terraform/terraform.tfvars.example | 6 ++++++ terraform/variables.tf | 28 ++++++++++++++++++++++++++++ terraform/versions.tf | 17 +++++++++++++++++ 8 files changed, 114 insertions(+) create mode 100644 terraform/.gitignore create mode 100644 terraform/README.md create mode 100644 terraform/dns.tf create mode 100644 terraform/main.tf create mode 100644 terraform/outputs.tf create mode 100644 terraform/terraform.tfvars.example create mode 100644 terraform/variables.tf create mode 100644 terraform/versions.tf diff --git a/terraform/.gitignore b/terraform/.gitignore new file mode 100644 index 0000000..6bc0c55 --- /dev/null +++ b/terraform/.gitignore @@ -0,0 +1,10 @@ +# State stays local per the design; a lost state file means rebuild, which is +# the point. Credentials never enter Git. +*.tfstate +*.tfstate.* +*.tfvars +!terraform.tfvars.example +.terraform/ +.terraform.lock.hcl +kubeconfig +crash.log diff --git a/terraform/README.md b/terraform/README.md new file mode 100644 index 0000000..8453055 --- /dev/null +++ b/terraform/README.md @@ -0,0 +1,30 @@ +# Terraform + +Provisions everything outside the cluster on `server0`. Rebuild is +`terraform apply` plus `kubectl apply -k deploy/`. + +Layout follows `OKF_CV_Website/architecture/terraform.md`: + +| File | Covers | +|---|---| +| `main.tf` | packages, 2 GB swap, containerd, `kubeadm init`, Calico, metrics-server, local-path provisioner, Caddy | +| `dns.tf` | apex A record at Cloudflare | +| `variables.tf` | server IP, SSH key, domain | +| `outputs.tf` | server IP, kubeconfig path, proxy URL | +| `versions.tf` | provider requirements, pinned after `terraform init` | + +Out of scope: anything inside namespace `cv`. Namespace, quota and workloads +are applied once by hand or by CI and then live in `deploy/`. + +## Usage + +```sh +cp terraform.tfvars.example terraform.tfvars # fill in +export CLOUDFLARE_API_TOKEN=... +terraform init +terraform plan +terraform apply +``` + +State stays local and out of Git. The kubeconfig this produces stays on this +machine. diff --git a/terraform/dns.tf b/terraform/dns.tf new file mode 100644 index 0000000..bd2df4c --- /dev/null +++ b/terraform/dns.tf @@ -0,0 +1,3 @@ +# DNS layer: A record for the apex domain pointing at the server's public IPv4. +# The zone is at Cloudflare; Caddy does its own ACME challenge, so no +# additional records are needed. diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 0000000..4497790 --- /dev/null +++ b/terraform/main.tf @@ -0,0 +1,6 @@ +# Server layer: packages, swap, containerd, kubeadm control plane, Calico, +# metrics-server, local-path provisioner, and Caddy. +# +# Terraform does not manage anything inside the cluster beyond the bootstrap +# (namespace cv, quota, addons). Workloads belong to kustomize. +# See OKF_CV_Website/architecture/terraform.md. diff --git a/terraform/outputs.tf b/terraform/outputs.tf new file mode 100644 index 0000000..dc6b7d4 --- /dev/null +++ b/terraform/outputs.tf @@ -0,0 +1,14 @@ +# Values other tooling and the operator need after apply. + +output "server_ip" { + description = "Public IPv4 of server0." + value = var.server_host +} + +output "proxy_url" { + description = "Public URL served by Caddy." + value = "https://${var.domain}" +} + +# Kubeconfig stays on this machine and never enters Git. Add its path here once +# main.tf writes it, e.g. "${path.module}/kubeconfig". diff --git a/terraform/terraform.tfvars.example b/terraform/terraform.tfvars.example new file mode 100644 index 0000000..002fcf1 --- /dev/null +++ b/terraform/terraform.tfvars.example @@ -0,0 +1,6 @@ +# Copy to terraform.tfvars and fill in. terraform.tfvars is Git-ignored. +server_host = "" +ssh_user = "root" +ssh_private_key_path = "~/.ssh/id_ed25519" +domain = "example.dev" +cloudflare_zone_id = "" diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 0000000..a8c8652 --- /dev/null +++ b/terraform/variables.tf @@ -0,0 +1,28 @@ +# Inputs: the server, its SSH access, and the domain. +# Nothing secret belongs here; secrets come from the environment or tfvars. + +variable "server_host" { + description = "Public IP or hostname of server0." + type = string +} + +variable "ssh_user" { + description = "SSH user Terraform logs in as." + type = string + default = "root" +} + +variable "ssh_private_key_path" { + description = "Path to the private key on this machine." + type = string +} + +variable "domain" { + description = "Apex domain served by the site, e.g. noelsabia.dev." + type = string +} + +variable "cloudflare_zone_id" { + description = "Zone ID of the domain in Cloudflare." + type = string +} diff --git a/terraform/versions.tf b/terraform/versions.tf new file mode 100644 index 0000000..25f6c56 --- /dev/null +++ b/terraform/versions.tf @@ -0,0 +1,17 @@ +# Provider requirements. + +# 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" +# } +# } +# }