serverctl/infrastructure/create-resources/hcloud.tf

40 lines
975 B
Terraform
Raw Normal View History

2022-02-18 15:50:37 +01:00
resource "hcloud_placement_group" "serverctl_master" {
name = "serverctl_master_group"
type = "spread"
}
variable "serverctl_master_count" {
default = 1
}
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"
ssh_keys = [
var.hcloud_serverctl_ssh_key_id
]
placement_group_id = hcloud_placement_group.serverctl_master.id
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 18:18:19 +01:00
resource "local_file" "hosts_cfg" {
content = templatefile("${path.module}/templates/hosts.tpl",
{
serverctl_masters = hcloud_server.serverctl_master.*.ipv4_address
}
)
filename = "ansible/inventory/hosts.cfg"
}