trails/infrastructure/terraform/main.tf
Ullrich Schäfer bf4eb81fcb
Add reverse DNS (PTR) records to Terraform config
IPv4 and IPv6 PTR records pointing to trails.cool.
These were applied to the server but missing from the committed config.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 00:15:28 +01:00

145 lines
2.7 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]
}
# Reverse DNS
resource "hcloud_rdns" "trails_ipv4" {
server_id = hcloud_server.trails.id
ip_address = hcloud_server.trails.ipv4_address
dns_ptr = "trails.cool"
}
resource "hcloud_rdns" "trails_ipv6" {
server_id = hcloud_server.trails.id
ip_address = hcloud_server.trails.ipv6_address
dns_ptr = "trails.cool"
}
# 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" "root_aaaa" {
zone = "trails.cool"
name = "@"
type = "AAAA"
ttl = 300
records = [{ value = hcloud_server.trails.ipv6_address }]
}
resource "hcloud_zone_rrset" "planner_a" {
zone = "trails.cool"
name = "planner"
type = "A"
ttl = 300
records = [{ value = hcloud_server.trails.ipv4_address }]
}
resource "hcloud_zone_rrset" "planner_aaaa" {
zone = "trails.cool"
name = "planner"
type = "AAAA"
ttl = 300
records = [{ value = hcloud_server.trails.ipv6_address }]
}
resource "hcloud_zone_rrset" "www_cname" {
zone = "trails.cool"
name = "www"
type = "CNAME"
ttl = 300
records = [{ value = "trails.cool." }]
}
# Outputs
output "server_ip" {
value = hcloud_server.trails.ipv4_address
}
output "domain" {
value = "trails.cool"
}
output "planner_domain" {
value = "planner.trails.cool"
}