Skip to content

Commit

Permalink
Merge pull request #3 from bayudwiyansatria/feature/multi-type-worker
Browse files Browse the repository at this point in the history
[GH-2] Add mutli type worker
  • Loading branch information
bayudwiyansatria committed Dec 4, 2021
2 parents 99157a7 + 6348c9e commit 55fcb9b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
21 changes: 15 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
@@ -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}"
Expand All @@ -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
}

#-----------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
22 changes: 14 additions & 8 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
]
}

0 comments on commit 55fcb9b

Please sign in to comment.