trails/infrastructure/terraform/main.tf
Ullrich Schäfer 9160301ab3
Add DNS records via Terraform, bump hcloud to v1.60 (#4)
- trails.cool and planner.trails.cool A records pointing to server
- Using hcloud_zone_rrset (native hcloud provider, no separate DNS provider)
- Bumped hcloud provider ~> 1.45 to ~> 1.60
- Server type updated to cx23

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 22:54:07 +01:00

107 lines
1.9 KiB
HCL

terraform {
required_version = ">= 1.0"
required_providers {
hcloud = {
source = "hetznercloud/hcloud"
version = "~> 1.60"
}
}
}
provider "hcloud" {
token = var.hcloud_token
}
resource "hcloud_ssh_key" "deploy" {
name = "trails-cool-deploy"
public_key = var.ssh_public_key
}
resource "hcloud_server" "trails" {
name = "trails-cool"
server_type = "cx23"
image = "ubuntu-24.04"
location = "fsn1"
ssh_keys = [hcloud_ssh_key.deploy.id]
labels = {
project = "trails-cool"
}
user_data = <<-EOF
#!/bin/bash
set -euo pipefail
# Install Docker
curl -fsSL https://get.docker.com | sh
# Install Docker Compose plugin
apt-get install -y docker-compose-plugin
# Create app directory
mkdir -p /opt/trails-cool
EOF
}
resource "hcloud_firewall" "trails" {
name = "trails-cool"
rule {
direction = "in"
protocol = "tcp"
port = "22"
source_ips = ["0.0.0.0/0", "::/0"]
}
rule {
direction = "in"
protocol = "tcp"
port = "80"
source_ips = ["0.0.0.0/0", "::/0"]
}
rule {
direction = "in"
protocol = "tcp"
port = "443"
source_ips = ["0.0.0.0/0", "::/0"]
}
}
resource "hcloud_firewall_attachment" "trails" {
firewall_id = hcloud_firewall.trails.id
server_ids = [hcloud_server.trails.id]
}
# DNS
resource "hcloud_zone_rrset" "root_a" {
zone = "trails.cool"
name = "@"
type = "A"
ttl = 300
records = [{ value = hcloud_server.trails.ipv4_address }]
}
resource "hcloud_zone_rrset" "planner_a" {
zone = "trails.cool"
name = "planner"
type = "A"
ttl = 300
records = [{ value = hcloud_server.trails.ipv4_address }]
}
# Outputs
output "server_ip" {
value = hcloud_server.trails.ipv4_address
}
output "domain" {
value = "trails.cool"
}
output "planner_domain" {
value = "planner.trails.cool"
}