generated from IBM/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpenShiftP-247: add loadbalancer logic into terraform
Signed-off-by: Paul Bastide <pbastide@us.ibm.com>
- Loading branch information
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Local .terraform directories | ||
_debug | ||
**/.terraform/* | ||
_scratch | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
################################################################ | ||
# Copyright 2025 - IBM Corporation. All rights reserved | ||
# SPDX-License-Identifier: Apache-2.0 | ||
################################################################ | ||
|
||
# ibm_is_lbs - https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/is_lb#private_ip-6 | ||
# in the resource provider that uses this data, we must add `lifecycle { ignore_changes = all }` | ||
|
||
data "ibm_resource_group" "group" { | ||
name = data.ibm_is_vpc.vpc.resource_group_name | ||
} | ||
|
||
# only get the subnets in the vpc | ||
data "ibm_is_subnets" "subnets" { | ||
vpc = data.ibm_is_vpc.vpc.id | ||
resource_group = data.ibm_resource_group.group.id | ||
} | ||
|
||
# gets all lbs in the region | ||
data "ibm_is_lbs" "lbs" { | ||
// Empty | ||
} | ||
|
||
locals { | ||
subnets_used_in_vpc = [for sn in data.ibm_is_subnets.subnets.subnets: sn.id] | ||
|
||
// Load Balancer Id | ||
subnets_from_lbs_with_ips = flatten([ | ||
for lb in data.ibm_is_lbs.lbs.load_balancers: | ||
flatten([ | ||
for sn in lb.subnets[*]: | ||
flatten([ | ||
for snx in data.ibm_is_subnets.subnets.subnets: | ||
sn.id == snx.id && snx.vpc == data.ibm_is_vpc.vpc.id && length(lb.private_ip) > 0 ? | ||
[{ | ||
id = lb.id | ||
lb_name = lb.name | ||
sn = sn | ||
vpc = data.ibm_is_vpc.vpc.id | ||
private_ip = lb.private_ip[*].address | ||
}] | ||
: [] | ||
]) | ||
]) | ||
]) | ||
|
||
load_balancer_ips = distinct(flatten([for slip in local.subnets_from_lbs_with_ips: | ||
!strcontains(slip.lb_name, "-api-")? | ||
flatten( | ||
[for pip in slip.private_ip: pip]): | ||
[]])) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters