2021-03-15 16:41:04 +08:00
|
|
|
|
|
|
|
terraform {
|
|
|
|
required_version = ">= 0.13.0"
|
|
|
|
}
|
|
|
|
provider "upcloud" {
|
|
|
|
# Your UpCloud credentials are read from environment variables:
|
|
|
|
username = var.UPCLOUD_USERNAME
|
|
|
|
password = var.UPCLOUD_PASSWORD
|
|
|
|
}
|
|
|
|
|
|
|
|
module "kubernetes" {
|
|
|
|
source = "./modules/kubernetes-cluster"
|
|
|
|
|
2021-09-11 04:55:21 +08:00
|
|
|
prefix = var.prefix
|
|
|
|
zone = var.zone
|
2021-03-15 16:41:04 +08:00
|
|
|
|
|
|
|
template_name = var.template_name
|
|
|
|
username = var.username
|
|
|
|
|
2021-09-11 04:55:21 +08:00
|
|
|
private_network_cidr = var.private_network_cidr
|
|
|
|
|
2021-03-15 16:41:04 +08:00
|
|
|
machines = var.machines
|
|
|
|
|
|
|
|
ssh_public_keys = var.ssh_public_keys
|
2022-05-12 01:15:03 +08:00
|
|
|
|
|
|
|
firewall_enabled = var.firewall_enabled
|
2022-07-19 15:18:06 +08:00
|
|
|
firewall_default_deny_in = var.firewall_default_deny_in
|
|
|
|
firewall_default_deny_out = var.firewall_default_deny_out
|
2022-05-12 01:15:03 +08:00
|
|
|
master_allowed_remote_ips = var.master_allowed_remote_ips
|
|
|
|
k8s_allowed_remote_ips = var.k8s_allowed_remote_ips
|
2022-07-19 15:18:06 +08:00
|
|
|
master_allowed_ports = var.master_allowed_ports
|
|
|
|
worker_allowed_ports = var.worker_allowed_ports
|
2022-05-12 01:15:03 +08:00
|
|
|
|
2024-03-23 07:08:59 +08:00
|
|
|
loadbalancer_enabled = var.loadbalancer_enabled
|
|
|
|
loadbalancer_plan = var.loadbalancer_plan
|
|
|
|
loadbalancer_outbound_proxy_protocol = var.loadbalancer_proxy_protocol ? "v2" : ""
|
|
|
|
loadbalancers = var.loadbalancers
|
2023-02-28 09:21:15 +08:00
|
|
|
|
|
|
|
server_groups = var.server_groups
|
2021-03-15 16:41:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Generate ansible inventory
|
|
|
|
#
|
|
|
|
|
|
|
|
data "template_file" "inventory" {
|
|
|
|
template = file("${path.module}/templates/inventory.tpl")
|
|
|
|
|
|
|
|
vars = {
|
2021-09-11 04:55:21 +08:00
|
|
|
connection_strings_master = join("\n", formatlist("%s ansible_user=ubuntu ansible_host=%s ip=%s etcd_member_name=etcd%d",
|
2021-03-15 16:41:04 +08:00
|
|
|
keys(module.kubernetes.master_ip),
|
2021-09-11 04:55:21 +08:00
|
|
|
values(module.kubernetes.master_ip).*.public_ip,
|
|
|
|
values(module.kubernetes.master_ip).*.private_ip,
|
2021-03-15 16:41:04 +08:00
|
|
|
range(1, length(module.kubernetes.master_ip) + 1)))
|
2021-09-11 04:55:21 +08:00
|
|
|
connection_strings_worker = join("\n", formatlist("%s ansible_user=ubuntu ansible_host=%s ip=%s",
|
2021-03-15 16:41:04 +08:00
|
|
|
keys(module.kubernetes.worker_ip),
|
2021-09-11 04:55:21 +08:00
|
|
|
values(module.kubernetes.worker_ip).*.public_ip,
|
|
|
|
values(module.kubernetes.worker_ip).*.private_ip))
|
2021-03-15 16:41:04 +08:00
|
|
|
list_master = join("\n", formatlist("%s",
|
|
|
|
keys(module.kubernetes.master_ip)))
|
|
|
|
list_worker = join("\n", formatlist("%s",
|
|
|
|
keys(module.kubernetes.worker_ip)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "null_resource" "inventories" {
|
|
|
|
provisioner "local-exec" {
|
|
|
|
command = "echo '${data.template_file.inventory.rendered}' > ${var.inventory_file}"
|
|
|
|
}
|
|
|
|
|
|
|
|
triggers = {
|
|
|
|
template = data.template_file.inventory.rendered
|
|
|
|
}
|
|
|
|
}
|