2024-09-25 11:23:52 +00:00
|
|
|
resource "hcloud_ssh_key" "openpgp_0xAB920993" {
|
|
|
|
name = "openpgp:0xAB920993"
|
|
|
|
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCkmWZmum4cVeDy5+9N1HdUzfnjEHSJ900ucD8F0wAy4MV1cdPYnZ4u5PFv5XMfmvA9SJ+VFsr0lhYlr+GQBG9aCCAdMJVVmEz3SccT6dp6ZYywT158RNshzfCe9ylWKK80+W7XnDXhdkec7aK+BQn5wOER3A3mUqRR0JDXWga9jyakH1K6OwXmQOO419bJWs2uCT1ZEgndHxKJEt2pEvoSz7z8p1SS2zyro+R3YtvL9WiDo3+0yPFYficNDr7s39yF5IJE+KTqAlCn5R2+kJ54lRmzB8oNS2jGwK2Q6wtph4AmfnlJTMODG2U2RjUltH2MIDXIYe2epATWL8qhkI4LTr38C7QR3DeJQsel/yTWdYqGakvU6Ge/xkbsaWOrSDTV3bPgKHzlL+dIKaGpV+5usZN4fpOLOb/nmYy3ekLpobzxza7rBRT2CxXS72DoPFaRE1ye7SxhcsLBNwre9YQFE4VvUZwJYkWz2V7eqGrk8VYnmQmT/bnUnMnVwMpeDc7pFKAFndIUxifoOj77c98Tdy3ncdS7SOd7+zRbLG+7k0UU1k89o1+tfREAddUJYR4RvB6g0kCyjpwOf1Pt4zhJR3y/zpsCCc5UnzK9X2kEo/8TSyvTr+GBiFVp5yLYgwCPJSNna33YX7+c3oLRM1QGgtqZk9qnGX9hgP8qpF8Akw== openpgp:0xAB920993"
|
|
|
|
}
|
|
|
|
|
|
|
|
data "template_file" "cloud_init" {
|
|
|
|
template = "${file("./tf-templates/cloud-init.yaml.tpl")}"
|
|
|
|
|
|
|
|
vars = {
|
|
|
|
tailscale_authkey = "${tailscale_tailnet_key.cloud_init_key.key}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
locals {
|
|
|
|
hetzner_hosts = {for key, val in var.hosts : key => val if val.provider == "hetzner"}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "hcloud_primary_ip" "node_ipv4_addresses" {
|
|
|
|
for_each = local.hetzner_hosts
|
|
|
|
name = "primary_ipv4_${each.value.hostname}"
|
|
|
|
datacenter = each.value.datacenter
|
|
|
|
type = "ipv4"
|
|
|
|
assignee_type = "server"
|
|
|
|
auto_delete = false
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "hcloud_primary_ip" "node_ipv6_addresses" {
|
|
|
|
for_each = local.hetzner_hosts
|
|
|
|
name = "primary_ipv6_${each.value.hostname}"
|
|
|
|
datacenter = each.value.datacenter
|
|
|
|
type = "ipv6"
|
|
|
|
assignee_type = "server"
|
|
|
|
auto_delete = false
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create a server
|
|
|
|
resource "hcloud_server" "nodes" {
|
|
|
|
for_each = local.hetzner_hosts
|
|
|
|
name = each.value.hostname
|
|
|
|
datacenter = each.value.datacenter
|
|
|
|
image = each.value.image
|
|
|
|
server_type = each.value.server_type
|
|
|
|
ssh_keys = [hcloud_ssh_key.openpgp_0xAB920993.id]
|
|
|
|
user_data = "${data.template_file.cloud_init.rendered}"
|
|
|
|
public_net {
|
|
|
|
ipv4 = hcloud_primary_ip.node_ipv4_addresses[each.key].id
|
|
|
|
ipv6 = hcloud_primary_ip.node_ipv6_addresses[each.key].id
|
|
|
|
}
|
|
|
|
lifecycle {
|
|
|
|
ignore_changes = [
|
|
|
|
ssh_keys,
|
|
|
|
user_data
|
|
|
|
]
|
2024-09-26 23:51:58 +00:00
|
|
|
prevent_destroy = true
|
2024-09-25 11:23:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "hcloud_rdns" "nodes_rdns" {
|
|
|
|
for_each = local.hetzner_hosts
|
|
|
|
server_id = hcloud_server.nodes[each.key].id
|
|
|
|
ip_address = hcloud_server.nodes[each.key].ipv4_address
|
|
|
|
dns_ptr = each.value.rdns
|
|
|
|
}
|