40 lines
962 B
HCL
40 lines
962 B
HCL
resource "hcloud_ssh_key" "cluster" {
|
|
name = "${var.prefix}-${var.name}-ssh-key"
|
|
public_key = var.ssh_public_key
|
|
}
|
|
|
|
resource "hcloud_server" "node" {
|
|
name = local.node_name
|
|
image = var.node_image
|
|
server_type = var.instance_type
|
|
location = var.hcloud_location
|
|
ssh_keys = [hcloud_ssh_key.cluster.id]
|
|
|
|
network {
|
|
network_id = var.hcloud_network_id
|
|
}
|
|
|
|
user_data = templatefile(
|
|
format("%s/files/userdata_node.template", path.module),
|
|
{
|
|
username = local.node_username
|
|
register_command = var.cluster_registration_command
|
|
}
|
|
)
|
|
|
|
provisioner "remote-exec" {
|
|
inline = [
|
|
"echo 'Waiting for cloud-init to complete...'",
|
|
"cloud-init status --wait > /dev/null",
|
|
"echo 'Completed cloud-init!'",
|
|
]
|
|
|
|
connection {
|
|
type = "ssh"
|
|
host = self.ipv4_address
|
|
user = local.node_username
|
|
private_key = var.ssh_private_key
|
|
}
|
|
}
|
|
}
|