44 lines
997 B
HCL

resource "hcloud_server" "private_node" {
count = var.server_count
name = "web${count.index + 1}"
image = var.server_image
server_type = var.server_type
location = var.location
labels = {
app = "web"
}
ssh_keys = hcloud_ssh_key.main[*].id
public_net {
ipv4_enabled = var.public_ipv4
ipv6_enabled = false
}
network {
network_id = hcloud_network.main.id
ip = cidrhost(hcloud_network_subnet.main.ip_range, count.index + 3)
}
depends_on = [
hcloud_network_subnet.main
]
}
resource "hcloud_network" "main" {
name = "main"
ip_range = var.network_ip_range
}
resource "hcloud_network_subnet" "main" {
network_id = hcloud_network.main.id
type = "cloud"
network_zone = var.network_zone
ip_range = var.server_subnetwork_ip_range
}
resource "hcloud_ssh_key" "main" {
count = length(var.ssh_keys)
name = "ssh-key${count.index}"
public_key = file(var.ssh_keys[count.index])
}