From 15b62cc7ce2c01352bab172eec31482f87c6f84b Mon Sep 17 00:00:00 2001 From: Robin Wallace Date: Wed, 26 Jun 2024 10:42:21 +0200 Subject: [PATCH] upcloud: v5.6.0 and better server groups (#11311) --- .../modules/kubernetes-cluster/main.tf | 44 ++++++++++++++----- .../modules/kubernetes-cluster/variables.tf | 2 +- .../modules/kubernetes-cluster/versions.tf | 2 +- contrib/terraform/upcloud/variables.tf | 2 +- contrib/terraform/upcloud/versions.tf | 2 +- 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/contrib/terraform/upcloud/modules/kubernetes-cluster/main.tf b/contrib/terraform/upcloud/modules/kubernetes-cluster/main.tf index 9639bdeae..54743a9e7 100644 --- a/contrib/terraform/upcloud/modules/kubernetes-cluster/main.tf +++ b/contrib/terraform/upcloud/modules/kubernetes-cluster/main.tf @@ -54,11 +54,12 @@ resource "upcloud_server" "master" { if machine.node_type == "master" } - hostname = "${local.resource-prefix}${each.key}" - plan = each.value.plan - cpu = each.value.plan == null ? each.value.cpu : null - mem = each.value.plan == null ? each.value.mem : null - zone = var.zone + hostname = "${local.resource-prefix}${each.key}" + plan = each.value.plan + cpu = each.value.plan == null ? null : each.value.cpu + mem = each.value.plan == null ? null : each.value.mem + zone = var.zone + server_group = each.value.server_group == null ? null : upcloud_server_group.server_groups[each.value.server_group].id template { storage = var.template_name @@ -111,11 +112,13 @@ resource "upcloud_server" "worker" { if machine.node_type == "worker" } - hostname = "${local.resource-prefix}${each.key}" - plan = each.value.plan - cpu = each.value.plan == null ? each.value.cpu : null - mem = each.value.plan == null ? each.value.mem : null - zone = var.zone + hostname = "${local.resource-prefix}${each.key}" + plan = each.value.plan + cpu = each.value.plan == null ? null : each.value.cpu + mem = each.value.plan == null ? null : each.value.mem + zone = var.zone + server_group = each.value.server_group == null ? null : upcloud_server_group.server_groups[each.value.server_group].id + template { storage = var.template_name @@ -513,7 +516,17 @@ resource "upcloud_loadbalancer" "lb" { name = "${local.resource-prefix}lb" plan = var.loadbalancer_plan zone = var.zone - network = upcloud_network.private.id + networks { + name = "Private-Net" + type = "private" + family = "IPv4" + network = upcloud_network.private.id + } + networks { + name = "Public-Net" + type = "public" + family = "IPv4" + } } resource "upcloud_loadbalancer_backend" "lb_backend" { @@ -534,6 +547,9 @@ resource "upcloud_loadbalancer_frontend" "lb_frontend" { mode = "tcp" port = each.value.port default_backend_name = upcloud_loadbalancer_backend.lb_backend[each.key].name + networks { + name = "Public-Net" + } } resource "upcloud_loadbalancer_static_backend_member" "lb_backend_member" { @@ -557,5 +573,9 @@ resource "upcloud_server_group" "server_groups" { title = each.key anti_affinity_policy = each.value.anti_affinity_policy labels = {} - members = [for server in each.value.servers : merge(upcloud_server.master, upcloud_server.worker)[server].id] + # Managed upstream via upcloud_server resource + members = [] + lifecycle { + ignore_changes = [members] + } } diff --git a/contrib/terraform/upcloud/modules/kubernetes-cluster/variables.tf b/contrib/terraform/upcloud/modules/kubernetes-cluster/variables.tf index 87e5e5370..530409f09 100644 --- a/contrib/terraform/upcloud/modules/kubernetes-cluster/variables.tf +++ b/contrib/terraform/upcloud/modules/kubernetes-cluster/variables.tf @@ -20,6 +20,7 @@ variable "machines" { cpu = string mem = string disk_size = number + server_group : string additional_disks = map(object({ size = number tier = string @@ -104,6 +105,5 @@ variable "server_groups" { type = map(object({ anti_affinity_policy = string - servers = list(string) })) } diff --git a/contrib/terraform/upcloud/modules/kubernetes-cluster/versions.tf b/contrib/terraform/upcloud/modules/kubernetes-cluster/versions.tf index 3138453be..81a2d1b57 100644 --- a/contrib/terraform/upcloud/modules/kubernetes-cluster/versions.tf +++ b/contrib/terraform/upcloud/modules/kubernetes-cluster/versions.tf @@ -3,7 +3,7 @@ terraform { required_providers { upcloud = { source = "UpCloudLtd/upcloud" - version = "~>2.12.0" + version = "~>5.6.0" } } required_version = ">= 0.13" diff --git a/contrib/terraform/upcloud/variables.tf b/contrib/terraform/upcloud/variables.tf index 9d8c90c17..58c626ab9 100644 --- a/contrib/terraform/upcloud/variables.tf +++ b/contrib/terraform/upcloud/variables.tf @@ -32,6 +32,7 @@ variable "machines" { cpu = string mem = string disk_size = number + server_group : string additional_disks = map(object({ size = number tier = string @@ -142,7 +143,6 @@ variable "server_groups" { type = map(object({ anti_affinity_policy = string - servers = list(string) })) default = {} diff --git a/contrib/terraform/upcloud/versions.tf b/contrib/terraform/upcloud/versions.tf index 3138453be..81a2d1b57 100644 --- a/contrib/terraform/upcloud/versions.tf +++ b/contrib/terraform/upcloud/versions.tf @@ -3,7 +3,7 @@ terraform { required_providers { upcloud = { source = "UpCloudLtd/upcloud" - version = "~>2.12.0" + version = "~>5.6.0" } } required_version = ">= 0.13"