Files
dokploy/terraform/main.tf
T

53 lines
1.3 KiB
Terraform

# 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
}