diff --git a/modules/vshn-lbaas-cloudscale/README.md b/modules/vshn-lbaas-cloudscale/README.md index 6fd4953..67abafa 100644 --- a/modules/vshn-lbaas-cloudscale/README.md +++ b/modules/vshn-lbaas-cloudscale/README.md @@ -23,6 +23,7 @@ The module provides variables to * specify a cloudscale.ch API secret for Floaty * specify the username for the APPUiO hieradata Git repository (see next sections for details). * provide an API token for control.vshn.net (see next sections for details). +* use pre-existing cloudscale floating IPs for api, ingress and egress. ## Required credentials diff --git a/modules/vshn-lbaas-cloudscale/hiera.tf b/modules/vshn-lbaas-cloudscale/hiera.tf index 5eb8ab8..74aaa86 100644 --- a/modules/vshn-lbaas-cloudscale/hiera.tf +++ b/modules/vshn-lbaas-cloudscale/hiera.tf @@ -17,10 +17,10 @@ module "hiera" { ingress_controller = var.ingress_controller lb_names = random_id.lb[*].hex hieradata_repo_user = var.hieradata_repo_user - api_vip = cidrhost(cloudscale_floating_ip.api_vip[0].network, 0) + api_vip = cidrhost(local.api_vip.network, 0) internal_vip = var.internal_vip - nat_vip = cidrhost(cloudscale_floating_ip.nat_vip[0].network, 0) - router_vip = cidrhost(cloudscale_floating_ip.router_vip[0].network, 0) + nat_vip = cidrhost(local.nat_vip.network, 0) + router_vip = cidrhost(local.router_vip.network, 0) team = var.team enable_proxy_protocol = var.enable_proxy_protocol diff --git a/modules/vshn-lbaas-cloudscale/main.tf b/modules/vshn-lbaas-cloudscale/main.tf index 18ebbde..cc6c653 100644 --- a/modules/vshn-lbaas-cloudscale/main.tf +++ b/modules/vshn-lbaas-cloudscale/main.tf @@ -1,5 +1,5 @@ resource "cloudscale_floating_ip" "api_vip" { - count = var.lb_count != 0 ? 1 : 0 + count = var.lb_count != 0 && !var.use_existing_vips ? 1 : 0 ip_version = 4 region_slug = var.region reverse_ptr = "api.${var.node_name_suffix}" @@ -13,8 +13,14 @@ resource "cloudscale_floating_ip" "api_vip" { } } +data "cloudscale_floating_ip" "api_vip" { + count = var.use_existing_vips ? 1 : 0 + ip_version = 4 + reverse_ptr = "api.${var.node_name_suffix}" +} + resource "cloudscale_floating_ip" "router_vip" { - count = var.lb_count != 0 ? 1 : 0 + count = var.lb_count != 0 && !var.use_existing_vips ? 1 : 0 ip_version = 4 region_slug = var.region reverse_ptr = "ingress.${var.node_name_suffix}" @@ -28,8 +34,14 @@ resource "cloudscale_floating_ip" "router_vip" { } } +data "cloudscale_floating_ip" "router_vip" { + count = var.use_existing_vips ? 1 : 0 + ip_version = 4 + reverse_ptr = "ingress.${var.node_name_suffix}" +} + resource "cloudscale_floating_ip" "nat_vip" { - count = var.lb_count != 0 ? 1 : 0 + count = var.lb_count != 0 && !var.use_existing_vips ? 1 : 0 ip_version = 4 region_slug = var.region reverse_ptr = "egress.${var.node_name_suffix}" @@ -43,6 +55,12 @@ resource "cloudscale_floating_ip" "nat_vip" { } } +data "cloudscale_floating_ip" "nat_vip" { + count = var.use_existing_vips ? 1 : 0 + ip_version = 4 + reverse_ptr = "egress.${var.node_name_suffix}" +} + resource "random_id" "lb" { count = var.lb_count prefix = "lb-" @@ -57,6 +75,10 @@ resource "cloudscale_server_group" "lb" { } locals { + api_vip = var.use_existing_vips ? data.cloudscale_floating_ip.api_vip[0] : cloudscale_floating_ip.api_vip[0] + router_vip = var.use_existing_vips ? data.cloudscale_floating_ip.router_vip[0] : cloudscale_floating_ip.router_vip[0] + nat_vip = var.use_existing_vips ? data.cloudscale_floating_ip.nat_vip[0] : cloudscale_floating_ip.nat_vip[0] + instance_fqdns = formatlist("%s.${var.node_name_suffix}", random_id.lb[*].hex) common_user_data = { diff --git a/modules/vshn-lbaas-cloudscale/outputs.tf b/modules/vshn-lbaas-cloudscale/outputs.tf index 24d6e29..872286c 100644 --- a/modules/vshn-lbaas-cloudscale/outputs.tf +++ b/modules/vshn-lbaas-cloudscale/outputs.tf @@ -1,13 +1,13 @@ output "api_vip" { - value = cloudscale_floating_ip.api_vip + value = local.api_vip } output "nat_vip" { - value = cloudscale_floating_ip.nat_vip + value = local.nat_vip } output "router_vip" { - value = cloudscale_floating_ip.router_vip + value = local.router_vip } output "server_names" { diff --git a/modules/vshn-lbaas-cloudscale/variables.tf b/modules/vshn-lbaas-cloudscale/variables.tf index 642a855..f74a645 100644 --- a/modules/vshn-lbaas-cloudscale/variables.tf +++ b/modules/vshn-lbaas-cloudscale/variables.tf @@ -106,3 +106,9 @@ variable "enable_proxy_protocol" { description = "Enable the PROXY protocol for the Router backends. WARNING: Connections will fail until you enable the same on the OpenShift router as well" default = false } + +variable "use_existing_vips" { + type = bool + description = "Use existing floating IPs for api_vip, router_vip and nat_vip. Manually set the reverse DNS info, so the correct data source is found." + default = false +}