From 6348c9e546ec819f375f34655ae28e8c07aa8bd0 Mon Sep 17 00:00:00 2001 From: Bayu Dwiyan Satria Date: Sat, 4 Dec 2021 17:47:49 +0800 Subject: [PATCH] [GH-2] Add mutli type worker --- main.tf | 21 +++++++++++++++------ variables.tf | 22 ++++++++++++++-------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/main.tf b/main.tf index 210f68b..790af68 100644 --- a/main.tf +++ b/main.tf @@ -1,6 +1,14 @@ #----------------------------------------------------------------------------------------------------------------------- # Global #----------------------------------------------------------------------------------------------------------------------- +locals { + worker_ids = flatten(module.worker.*.ids) + worker_ips = flatten(module.worker.*.ips) + depends_on = [ + module.worker + ] +} + resource "hcloud_ssh_key" "admin" { count = length(var.cluster_admin_ssh_keys) name = "admin-${count.index + 1}" @@ -25,12 +33,13 @@ module "master" { #----------------------------------------------------------------------------------------------------------------------- module "worker" { + count = length(var.worker_type) source = "bayudwiyansatria/server/hcloud" hcloud_token = var.hcloud_token server_keys = hcloud_ssh_key.admin.*.id - server_name = "${var.cluster_name}-worker" - server_count = var.worker_count - server_type = var.worker_type + server_name = "${var.cluster_name}-worker-${var.worker_type[count.index].type}" + server_count = var.worker_type[count.index].count + server_type = var.worker_type[count.index].type } #----------------------------------------------------------------------------------------------------------------------- @@ -59,8 +68,8 @@ resource "hcloud_server_network" "master_network" { } resource "hcloud_server_network" "worker_network" { - count = var.worker_count - server_id = module.worker.ids[count.index] + count = length(local.worker_ids) + server_id = local.worker_ids[count.index] network_id = module.network.ids depends_on = [ module.worker, @@ -76,7 +85,7 @@ module "kubernetes" { source = "bayudwiyansatria/cloud-bootstrap/kubernetes" docker_enabled = true master_host = module.master.ips - worker_host = module.worker.ips + worker_host = local.worker_ips ssh_private_key = var.cluster_admin_ssh_access depends_on = [ module.master, diff --git a/variables.tf b/variables.tf index cd41ee4..b7db091 100644 --- a/variables.tf +++ b/variables.tf @@ -31,14 +31,20 @@ variable "master_type" { default = "cx21" } -variable "worker_count" { - type = number - description = "Number of workers nodes" - default = 2 -} - variable "worker_type" { - type = string + type = list(object({ + count = number, + type = string + })) description = "For more types have a look at https://www.hetzner.de/cloud" - default = "cx21" + default = [ + { + count = 1 + type = "cx21", + }, + { + count = 1 + type = "cpx11", + } + ] } \ No newline at end of file