Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional support for using existing floating IPs #53

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/vshn-lbaas-cloudscale/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions modules/vshn-lbaas-cloudscale/hiera.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 25 additions & 3 deletions modules/vshn-lbaas-cloudscale/main.tf
Original file line number Diff line number Diff line change
@@ -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}"
Expand All @@ -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}"
Expand All @@ -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}"
Expand All @@ -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-"
Expand All @@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions modules/vshn-lbaas-cloudscale/outputs.tf
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
6 changes: 6 additions & 0 deletions modules/vshn-lbaas-cloudscale/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading