serverctl/infrastructure/create-resources/hcloud.tf

119 lines
2.7 KiB
Terraform
Raw Normal View History

2022-02-19 21:29:38 +01:00
variable "serverctl_master_count" {
2022-02-19 22:11:50 +01:00
default = 0
2022-02-19 21:29:38 +01:00
}
variable "serverctl_node_count" {
2022-02-19 22:11:50 +01:00
default = 0
2022-02-19 21:29:38 +01:00
}
2022-02-24 13:57:19 +01:00
variable "serverctl_mesh_count" {
2022-02-24 14:03:42 +01:00
default = 0
2022-02-24 13:57:19 +01:00
}
2022-02-19 21:29:38 +01:00
2022-02-18 15:50:37 +01:00
resource "hcloud_placement_group" "serverctl_master" {
name = "serverctl_master_group"
type = "spread"
}
resource "hcloud_server" "serverctl_master" {
2022-02-19 18:18:19 +01:00
count = var.serverctl_master_count
name = "serverctl-master-${count.index}"
image = "debian-11"
2022-02-18 15:50:37 +01:00
server_type = "cx11"
2022-02-24 13:57:19 +01:00
ssh_keys = [
2022-02-18 15:50:37 +01:00
var.hcloud_serverctl_ssh_key_id
]
placement_group_id = hcloud_placement_group.serverctl_master.id
2022-02-19 20:23:54 +01:00
lifecycle {
create_before_destroy = true
}
2022-02-18 15:50:37 +01:00
provisioner "remote-exec" {
inline = ["sudo apt update", "sudo apt install python3 -y", "echo Done!"]
connection {
2022-02-19 18:18:19 +01:00
host = self.ipv4_address
type = "ssh"
user = "root"
2022-02-18 15:50:37 +01:00
private_key = file(var.pvt_key)
}
}
}
2022-02-19 21:29:38 +01:00
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"
2022-02-24 13:57:19 +01:00
ssh_keys = [
2022-02-19 21:29:38 +01:00
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)
}
}
}
2022-02-24 13:57:19 +01:00
resource "hcloud_placement_group" "serverctl_mesh" {
name = "serverctl_mesh_group"
type = "spread"
}
resource "hcloud_server" "serverctl_mesh" {
count = var.serverctl_mesh_count
name = "serverctl-mesh-${count.index}"
image = "debian-11"
server_type = "cx11"
ssh_keys = [
var.hcloud_serverctl_ssh_key_id
]
placement_group_id = hcloud_placement_group.serverctl_mesh.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)
}
}
}
2022-02-19 18:18:19 +01:00
resource "local_file" "hosts_cfg" {
2022-02-24 13:57:19 +01:00
content = templatefile("${path.module}/templates/hosts.tftpl",
2022-02-19 18:18:19 +01:00
{
2022-02-24 13:57:19 +01:00
serverctl_masters = hcloud_server.serverctl_master.*.ipv4_address
serverctl_nodes = hcloud_server.serverctl_node.*.ipv4_address
serverctl_mesh_nodes = hcloud_server.serverctl_mesh.*.ipv4_address
2022-02-19 18:18:19 +01:00
}
)
filename = "ansible/inventory/hosts.cfg"
}