infrastructure-ng/id.tjo.space/terraform/main.tf

66 lines
1.3 KiB
Terraform
Raw Normal View History

2025-03-05 21:43:20 +00:00
resource "hcloud_ssh_key" "main" {
for_each = var.ssh_keys
2025-03-06 19:04:18 +00:00
2025-03-05 21:43:20 +00:00
name = each.key
2025-03-06 19:04:18 +00:00
public_key = each.value
2025-03-05 21:43:20 +00:00
}
resource "hcloud_server" "main" {
2025-03-06 19:04:18 +00:00
for_each = toset(var.nodes)
name = "${each.key}.id.tjo.space"
2025-03-05 21:43:20 +00:00
image = "ubuntu-24.04"
server_type = "cax11"
datacenter = "hel1-dc2"
public_net {
ipv4_enabled = true
ipv6_enabled = true
}
backups = true
2025-03-06 19:04:18 +00:00
ssh_keys = [for key, value in var.ssh_keys : hcloud_ssh_key.main[key].id]
2025-03-05 21:43:20 +00:00
user_data = <<-EOF
#cloud-config
2025-03-06 19:31:24 +00:00
hostname: "${each.key}"
2025-03-05 21:43:20 +00:00
fqdn: id.tjo.space
prefer_fqdn_over_hostname: true
packages:
- git
2025-03-05 21:49:55 +00:00
- curl
2025-03-05 21:43:20 +00:00
package_update: true
package_upgrade: true
power_state:
mode: reboot
swap:
filename: /swapfile
size: 512M
runcmd:
2025-03-06 19:31:24 +00:00
- "curl -sL https://raw.githubusercontent.com/tjo-space/tjo-space-infrastructure/refs/heads/main/id.tjo.space/install.sh | bash"
EOF
2025-03-05 21:43:20 +00:00
}
resource "dnsimple_zone_record" "a" {
2025-03-06 19:04:18 +00:00
for_each = toset(var.nodes)
2025-03-05 21:43:20 +00:00
zone_name = "tjo.space"
2025-03-06 19:10:20 +00:00
name = "next.id"
2025-03-06 19:04:18 +00:00
value = hcloud_server.main[each.key].ipv4_address
2025-03-05 21:43:20 +00:00
type = "A"
ttl = 300
}
resource "dnsimple_zone_record" "aaaa" {
2025-03-06 19:04:18 +00:00
for_each = toset(var.nodes)
2025-03-05 21:43:20 +00:00
zone_name = "tjo.space"
2025-03-06 19:10:20 +00:00
name = "next.id"
2025-03-06 19:04:18 +00:00
value = hcloud_server.main[each.key].ipv6_address
2025-03-05 21:43:20 +00:00
type = "AAAA"
ttl = 300
}