feat: terraform + ansible config to provision a host on hetzner & set cloudflare DNS

This commit is contained in:
2026-08-18 13:01:36 +02:00
commit fecf871eb1
9 changed files with 181 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
# SSH key shared with the VPS
resource "hcloud_ssh_key" "ansible" {
name = var.project_name
public_key = var.ssh_public_key
}
# Provision a small Hetzner Cloud VPS
resource "hcloud_server" "dokploy" {
name = var.project_name
image = var.hcloud_image
server_type = var.hcloud_server_type
location = var.hcloud_location
ssh_keys = [hcloud_ssh_key.ansible.id]
public_net {
ipv4_enabled = true
}
}
# Resolve the Cloudflare zone from its apex domain name
data "cloudflare_zone" "zone" {
filter = {
name = var.domain_name
}
}
locals {
public_ip = hcloud_server.dokploy.ipv4_address
}
# Automatically publish the VPS IP as a Cloudflare A record
resource "cloudflare_dns_record" "a" {
zone_id = data.cloudflare_zone.zone.id
name = var.record_name
type = "A"
content = local.public_ip
proxied = var.cloudflare_proxied
ttl = var.cloudflare_proxied ? 1 : 3600
}
# Write IP to Ansible inventory
resource "local_file" "ansible_inventory" {
content = templatefile("${path.module}/../ansible/inventory.tpl", {
public_ip = local.public_ip
})
filename = "${path.module}/../ansible/inventory.ini"
}
output "public_ip" {
description = "The public IPv4 address of the provisioned Hetzner Cloud VPS"
value = local.public_ip
}