serverctl/infrastructure/create-resources/hcloud.tf
Kasper Juul Hermansen e48e6f0c3d
All checks were successful
continuous-integration/drone/push Build is passing
Update 'infrastructure/create-resources/hcloud.tf'
2022-03-08 15:23:11 +01:00

82 lines
1.8 KiB
HCL

variable "serverctl_master_count" {
default = 1
}
variable "serverctl_node_count" {
default = 1
}
resource "hcloud_placement_group" "serverctl_master" {
name = "serverctl_master_group"
type = "spread"
}
resource "hcloud_server" "serverctl_master" {
count = var.serverctl_master_count
name = "serverctl-master-${count.index}"
image = "debian-11"
server_type = "cx11"
ssh_keys = [
var.hcloud_serverctl_ssh_key_id
]
placement_group_id = hcloud_placement_group.serverctl_master.id
lifecycle {
create_before_destroy = true
}
provisioner "remote-exec" {
inline = ["sudo apt update", "sudo apt install python3 -y", "echo Done!"]
connection {
host = self.ipv4_address
type = "ssh"
user = "root"
private_key = file(var.pvt_key)
}
}
}
resource "hcloud_placement_group" "serverctl_node" {
name = "serverctl_node_group"
type = "spread"
}
resource "hcloud_server" "serverctl_node" {
count = var.serverctl_node_count
name = "serverctl-node-${count.index}"
image = "debian-11"
server_type = "cx11"
ssh_keys = [
var.hcloud_serverctl_ssh_key_id
]
placement_group_id = hcloud_placement_group.serverctl_node.id
lifecycle {
create_before_destroy = true
}
provisioner "remote-exec" {
inline = ["sudo apt update", "sudo apt install python3 -y", "echo Done!"]
connection {
host = self.ipv4_address
type = "ssh"
user = "root"
private_key = file(var.pvt_key)
}
}
}
resource "local_file" "hosts_cfg" {
content = templatefile("${path.module}/templates/hosts.tftpl",
{
serverctl_masters = hcloud_server.serverctl_master.*.ipv4_address
serverctl_nodes = hcloud_server.serverctl_node.*.ipv4_address
}
)
filename = "ansible/inventory/hosts.cfg"
}