feat(terraform): create hetzner server and apex A record
This commit is contained in:
1 parent
3335482efc
commit
8e0c1a8796
6 files changed
+96
-26
No files matched your search
@@ -1,3 +1,18 @@
|
|||||||
# DNS layer: A record for the apex domain pointing at the server's public IPv4.
|
# 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
|
# The zone is at Cloudflare; Caddy does its own ACME challenge, so no
|
||||||
# additional records are needed.
|
# additional records are needed.
|
||||||
|
#
|
||||||
|
# proxied = false on purpose: an orange-cloud record terminates TLS at
|
||||||
|
# Cloudflare and Caddy can never complete its ACME challenge.
|
||||||
|
|
||||||
|
provider "cloudflare" {}
|
||||||
|
|
||||||
|
resource "cloudflare_dns_record" "apex" {
|
||||||
|
zone_id = var.cloudflare_zone_id
|
||||||
|
name = var.domain
|
||||||
|
type = "A"
|
||||||
|
content = hcloud_server.server0.ipv4_address
|
||||||
|
ttl = 300
|
||||||
|
proxied = false
|
||||||
|
comment = "server0, managed by Terraform"
|
||||||
|
}
|
||||||
+25
-3
@@ -1,6 +1,28 @@
|
|||||||
# Server layer: packages, swap, containerd, kubeadm control plane, Calico,
|
# Server layer: creates server0 at Hetzner and installs the SSH key at boot.
|
||||||
# metrics-server, local-path provisioner, and Caddy.
|
# Packages, swap, containerd, kubeadm, addons and Caddy follow in later steps
|
||||||
|
# over SSH; see plan.md.
|
||||||
#
|
#
|
||||||
# Terraform does not manage anything inside the cluster beyond the bootstrap
|
# Terraform does not manage anything inside the cluster beyond the bootstrap
|
||||||
# (namespace cv, quota, addons). Workloads belong to kustomize.
|
# (namespace cv, quota, addons). Workloads belong to kustomize.
|
||||||
# See OKF_CV_Website/architecture/terraform.md.
|
|
||||||
|
provider "hcloud" {}
|
||||||
|
|
||||||
|
resource "hcloud_ssh_key" "cv_infra" {
|
||||||
|
name = "cv-infra"
|
||||||
|
public_key = file(pathexpand(var.ssh_public_key_path))
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "hcloud_server" "server0" {
|
||||||
|
name = "server0"
|
||||||
|
server_type = var.server_type
|
||||||
|
image = var.server_image
|
||||||
|
location = var.server_location
|
||||||
|
ssh_keys = [hcloud_ssh_key.cv_infra.id]
|
||||||
|
labels = { role = "cv-control-plane" }
|
||||||
|
|
||||||
|
public_net {
|
||||||
|
ipv4_enabled = true
|
||||||
|
# No AAAA record is managed, so do not pay for an unused IPv6.
|
||||||
|
ipv6_enabled = false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,12 @@
|
|||||||
|
|
||||||
output "server_ip" {
|
output "server_ip" {
|
||||||
description = "Public IPv4 of server0."
|
description = "Public IPv4 of server0."
|
||||||
value = var.server_host
|
value = hcloud_server.server0.ipv4_address
|
||||||
|
}
|
||||||
|
|
||||||
|
output "ssh_command" {
|
||||||
|
description = "Ready-to-paste SSH command for server0."
|
||||||
|
value = "ssh -i ${var.ssh_private_key_path} ${var.ssh_user}@${hcloud_server.server0.ipv4_address}"
|
||||||
}
|
}
|
||||||
|
|
||||||
output "proxy_url" {
|
output "proxy_url" {
|
||||||
|
|||||||
+18
-15
@@ -20,12 +20,14 @@ on an empty machine. See `OKF_CV_Website/architecture/terraform.md`.
|
|||||||
|
|
||||||
## Steps
|
## Steps
|
||||||
|
|
||||||
### 1. Server source
|
### 1. Server source — done
|
||||||
|
|
||||||
Decide the two open questions above. Write them into this file so later steps
|
`main.tf` creates `server0` as a Hetzner `hcloud_server` (`cx22`, `ubuntu-24.04`)
|
||||||
have a fixed target.
|
and registers `~/.ssh/cv_infra.pub` as an `hcloud_ssh_key`, so the key is in
|
||||||
|
`authorized_keys` before the machine boots. `terraform.md` and `README.md` still
|
||||||
|
describe `server_host` as an input; they need updating.
|
||||||
|
|
||||||
Check: one sentence answers "what does `apply` create?".
|
Check: `terraform output server_ip` returns the address.
|
||||||
|
|
||||||
### 2. SSH key — done
|
### 2. SSH key — done
|
||||||
|
|
||||||
@@ -34,11 +36,10 @@ server during creation (step 6), not after.
|
|||||||
|
|
||||||
Check: `ssh-keygen -y -f ~/.ssh/cv_infra` prints the public key.
|
Check: `ssh-keygen -y -f ~/.ssh/cv_infra` prints the public key.
|
||||||
|
|
||||||
### 3. Provider and versions
|
### 3. Provider and versions — done
|
||||||
|
|
||||||
Uncomment `versions.tf`, set `required_version` and the provider(s), run
|
`versions.tf` pins `cloudflare` 5.28.1 and `hcloud` 1.70.2; init and validate
|
||||||
`terraform init`. Commit `.terraform.lock.hcl` is currently ignored — decide
|
pass. `required_version` and a `null` provider still need adding before step 7.
|
||||||
whether that stays.
|
|
||||||
|
|
||||||
Check: `terraform init` succeeds, `.terraform.lock.hcl` exists.
|
Check: `terraform init` succeeds, `.terraform.lock.hcl` exists.
|
||||||
|
|
||||||
@@ -50,20 +51,22 @@ Copy `terraform.tfvars.example` to `terraform.tfvars`, fill `server_host`,
|
|||||||
|
|
||||||
Check: `terraform validate` passes.
|
Check: `terraform validate` passes.
|
||||||
|
|
||||||
### 5. DNS first
|
### 5. DNS — written
|
||||||
|
|
||||||
Write `dns.tf`: one `cloudflare_record` for the apex A record. Smallest real
|
`dns.tf` creates `cloudflare_dns_record.apex` from
|
||||||
resource, and it exercises provider, token and zone ID with no server involved.
|
`hcloud_server.server0.ipv4_address`, so the record can only be created after
|
||||||
|
the server — one `apply` does both, in order. `proxied = false` is required for
|
||||||
|
Caddy's ACME challenge.
|
||||||
|
|
||||||
Check: `terraform apply` creates the record, `dig +short <domain>` returns the
|
Check: `terraform apply` creates the record, `dig +short <domain>` returns the
|
||||||
server IP.
|
server IP.
|
||||||
|
|
||||||
### 6. Server creation
|
### 6. Server creation — written
|
||||||
|
|
||||||
Add the server resource with the SSH public key attached at creation.
|
`main.tf` creates the server with the SSH public key attached at creation.
|
||||||
|
|
||||||
Check: `terraform apply` creates it, `ssh -i ~/.ssh/cv_infra <user>@<host>`
|
Check: `terraform apply` creates it, `terraform output ssh_command` works
|
||||||
works without a password.
|
without a password.
|
||||||
|
|
||||||
### 7. Connection skeleton
|
### 7. Connection skeleton
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
# Copy to terraform.tfvars and fill in. terraform.tfvars is Git-ignored.
|
# Copy to terraform.tfvars and fill in. terraform.tfvars is Git-ignored.
|
||||||
server_host = ""
|
|
||||||
ssh_user = "root"
|
ssh_user = "root"
|
||||||
ssh_private_key_path = "~/.ssh/id_ed25519"
|
ssh_private_key_path = "~/.ssh/cv_infra"
|
||||||
|
ssh_public_key_path = "~/.ssh/cv_infra.pub"
|
||||||
|
server_type = "cx22"
|
||||||
|
server_image = "ubuntu-24.04"
|
||||||
|
server_location = "nbg1"
|
||||||
domain = "example.dev"
|
domain = "example.dev"
|
||||||
cloudflare_zone_id = ""
|
cloudflare_zone_id = ""
|
||||||
+27
-5
@@ -1,10 +1,8 @@
|
|||||||
# Inputs: the server, its SSH access, and the domain.
|
# Inputs: the server, its SSH access, and the domain.
|
||||||
# Nothing secret belongs here; secrets come from the environment or tfvars.
|
# Nothing secret belongs here; secrets come from the environment or tfvars.
|
||||||
|
#
|
||||||
variable "server_host" {
|
# server_host is gone: Terraform now creates the server, so its IP is an output
|
||||||
description = "Public IP or hostname of server0."
|
# rather than an input.
|
||||||
type = string
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "ssh_user" {
|
variable "ssh_user" {
|
||||||
description = "SSH user Terraform logs in as."
|
description = "SSH user Terraform logs in as."
|
||||||
@@ -17,6 +15,30 @@ variable "ssh_private_key_path" {
|
|||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "ssh_public_key_path" {
|
||||||
|
description = "Path to the matching public key, installed at server creation."
|
||||||
|
type = string
|
||||||
|
default = "~/.ssh/cv_infra.pub"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "server_type" {
|
||||||
|
description = "Hetzner server type. cx22 gives 2 vCPU and 4 GB, the floor for a control plane."
|
||||||
|
type = string
|
||||||
|
default = "cx22"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "server_image" {
|
||||||
|
description = "Hetzner image for the base system."
|
||||||
|
type = string
|
||||||
|
default = "ubuntu-24.04"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "server_location" {
|
||||||
|
description = "Hetzner location, e.g. nbg1, fsn1, hel1."
|
||||||
|
type = string
|
||||||
|
default = "nbg1"
|
||||||
|
}
|
||||||
|
|
||||||
variable "domain" {
|
variable "domain" {
|
||||||
description = "Apex domain served by the site, e.g. noelsabia.dev."
|
description = "Apex domain served by the site, e.g. noelsabia.dev."
|
||||||
type = string
|
type = string
|
||||||
|
|||||||
Reference in new issue
Block a user