From 57f65da9e4be7d623eaf4bc7c185fe960dee0f3b Mon Sep 17 00:00:00 2001 From: Fredrik Liv Date: Wed, 24 Jul 2024 16:54:45 +0200 Subject: [PATCH] Upcloud: Added support for deprecated network field for loadbalancers --- contrib/terraform/upcloud/README.md | 1 + contrib/terraform/upcloud/main.tf | 1 + .../modules/kubernetes-cluster/main.tf | 38 +++++++++++++------ .../modules/kubernetes-cluster/variables.tf | 5 +++ contrib/terraform/upcloud/variables.tf | 7 ++++ 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/contrib/terraform/upcloud/README.md b/contrib/terraform/upcloud/README.md index cd4874a0d..81472c100 100644 --- a/contrib/terraform/upcloud/README.md +++ b/contrib/terraform/upcloud/README.md @@ -134,6 +134,7 @@ terraform destroy --var-file cluster-settings.tfvars \ * `end_address`: End of address range to allow * `loadbalancer_enabled`: Enable managed load balancer * `loadbalancer_plan`: Plan to use for load balancer *(development|production-small)* +* `loadbalancer_legacy_network`: If the loadbalancer should use the deprecated network field instead of networks blocks. You probably want to have this set to false (default value) * `loadbalancers`: Ports to load balance and which machines to forward to. Key of this object will be used as the name of the load balancer frontends/backends * `port`: Port to load balance. * `target_port`: Port to the backend servers. diff --git a/contrib/terraform/upcloud/main.tf b/contrib/terraform/upcloud/main.tf index e5ee1c005..d6a7e95d2 100644 --- a/contrib/terraform/upcloud/main.tf +++ b/contrib/terraform/upcloud/main.tf @@ -36,6 +36,7 @@ module "kubernetes" { loadbalancer_enabled = var.loadbalancer_enabled loadbalancer_plan = var.loadbalancer_plan loadbalancer_outbound_proxy_protocol = var.loadbalancer_proxy_protocol ? "v2" : "" + loadbalancer_legacy_network = var.loadbalancer_legacy_network loadbalancers = var.loadbalancers router_enable = var.router_enable diff --git a/contrib/terraform/upcloud/modules/kubernetes-cluster/main.tf b/contrib/terraform/upcloud/modules/kubernetes-cluster/main.tf index 0a5bd40d0..54b9bf226 100644 --- a/contrib/terraform/upcloud/modules/kubernetes-cluster/main.tf +++ b/contrib/terraform/upcloud/modules/kubernetes-cluster/main.tf @@ -549,16 +549,27 @@ resource "upcloud_loadbalancer" "lb" { name = "${local.resource-prefix}lb" plan = var.loadbalancer_plan zone = var.private_cloud ? var.public_zone : var.zone - networks { - name = "Private-Net" - type = "private" - family = "IPv4" - network = upcloud_network.private.id + network = var.loadbalancer_legacy_network ? upcloud_network.private.id : null + + dynamic "networks" { + for_each = var.loadbalancer_legacy_network ? [] : [1] + + content { + name = "Private-Net" + type = "private" + family = "IPv4" + network = upcloud_network.private.id + } } - networks { - name = "Public-Net" - type = "public" - family = "IPv4" + + dynamic "networks" { + for_each = var.loadbalancer_legacy_network ? [] : [1] + + content { + name = "Public-Net" + type = "public" + family = "IPv4" + } } lifecycle { @@ -584,8 +595,13 @@ 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" + + dynamic "networks" { + for_each = var.loadbalancer_legacy_network ? [] : [1] + + content { + name = "Public-Net" + } } dynamic "networks" { diff --git a/contrib/terraform/upcloud/modules/kubernetes-cluster/variables.tf b/contrib/terraform/upcloud/modules/kubernetes-cluster/variables.tf index 5c010cf4f..afff410ca 100644 --- a/contrib/terraform/upcloud/modules/kubernetes-cluster/variables.tf +++ b/contrib/terraform/upcloud/modules/kubernetes-cluster/variables.tf @@ -98,6 +98,11 @@ variable "loadbalancer_outbound_proxy_protocol" { type = string } +variable "loadbalancer_legacy_network" { + type = bool + default = false +} + variable "loadbalancers" { description = "Load balancers" diff --git a/contrib/terraform/upcloud/variables.tf b/contrib/terraform/upcloud/variables.tf index d28b02fd9..db398d7a5 100644 --- a/contrib/terraform/upcloud/variables.tf +++ b/contrib/terraform/upcloud/variables.tf @@ -136,6 +136,13 @@ variable "loadbalancer_proxy_protocol" { default = false } +variable "loadbalancer_legacy_network" { + description = "If the loadbalancer should use the deprecated network field instead of networks blocks. You probably want to have this set to false" + + type = bool + default = false +} + variable "loadbalancers" { description = "Load balancers"