2021-10-08 01:11:46 +08:00
|
|
|
provider "hcloud" {}
|
|
|
|
|
|
|
|
module "kubernetes" {
|
|
|
|
source = "./modules/kubernetes-cluster"
|
2023-05-08 08:15:16 +08:00
|
|
|
# source = "./modules/kubernetes-cluster-flatcar"
|
2021-10-08 01:11:46 +08:00
|
|
|
|
|
|
|
prefix = var.prefix
|
|
|
|
|
|
|
|
zone = var.zone
|
|
|
|
|
|
|
|
machines = var.machines
|
|
|
|
|
2022-12-28 10:17:28 +08:00
|
|
|
#only for flatcar
|
|
|
|
#ssh_private_key_path = var.ssh_private_key_path
|
|
|
|
|
2021-10-08 01:11:46 +08:00
|
|
|
ssh_public_keys = var.ssh_public_keys
|
2023-05-08 08:15:16 +08:00
|
|
|
network_zone = var.network_zone
|
2021-10-08 01:11:46 +08:00
|
|
|
|
|
|
|
ssh_whitelist = var.ssh_whitelist
|
|
|
|
api_server_whitelist = var.api_server_whitelist
|
|
|
|
nodeport_whitelist = var.nodeport_whitelist
|
|
|
|
ingress_whitelist = var.ingress_whitelist
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Generate ansible inventory
|
|
|
|
#
|
|
|
|
|
2023-05-08 08:15:16 +08:00
|
|
|
locals {
|
|
|
|
inventory = templatefile(
|
|
|
|
"${path.module}/templates/inventory.tpl",
|
|
|
|
{
|
|
|
|
connection_strings_master = join("\n", formatlist("%s ansible_user=ubuntu ansible_host=%s ip=%s etcd_member_name=etcd%d",
|
|
|
|
keys(module.kubernetes.master_ip_addresses),
|
|
|
|
values(module.kubernetes.master_ip_addresses).*.public_ip,
|
|
|
|
values(module.kubernetes.master_ip_addresses).*.private_ip,
|
|
|
|
range(1, length(module.kubernetes.master_ip_addresses) + 1)))
|
|
|
|
connection_strings_worker = join("\n", formatlist("%s ansible_user=ubuntu ansible_host=%s ip=%s",
|
|
|
|
keys(module.kubernetes.worker_ip_addresses),
|
|
|
|
values(module.kubernetes.worker_ip_addresses).*.public_ip,
|
|
|
|
values(module.kubernetes.worker_ip_addresses).*.private_ip))
|
|
|
|
list_master = join("\n", keys(module.kubernetes.master_ip_addresses))
|
|
|
|
list_worker = join("\n", keys(module.kubernetes.worker_ip_addresses))
|
|
|
|
network_id = module.kubernetes.network_id
|
|
|
|
}
|
|
|
|
)
|
2021-10-08 01:11:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "null_resource" "inventories" {
|
|
|
|
provisioner "local-exec" {
|
2023-05-08 08:15:16 +08:00
|
|
|
command = "echo '${local.inventory}' > ${var.inventory_file}"
|
2021-10-08 01:11:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
triggers = {
|
2023-05-08 08:15:16 +08:00
|
|
|
template = local.inventory
|
2021-10-08 01:11:46 +08:00
|
|
|
}
|
2023-02-06 17:35:16 +08:00
|
|
|
}
|