Skip to content

Commit

Permalink
OpenShiftP-247: refine the output
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Bastide <pbastide@us.ibm.com>
  • Loading branch information
prb112 committed Jan 31, 2025
1 parent 6df1eb8 commit 007af2d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
52 changes: 26 additions & 26 deletions modules/1_vpc_support/find_lbs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,41 @@ data "ibm_resource_group" "group" {

# only get the subnets in the vpc
data "ibm_is_subnets" "subnets" {
vpc = data.ibm_is_vpc.vpc.id
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
// Empty
}

locals {
subnets_used_in_vpc = [for sn in data.ibm_is_subnets.subnets.subnets: sn.id]
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 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]):
[]]))
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]) :
[]]))
}
4 changes: 2 additions & 2 deletions modules/1_vpc_support/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ output "transit_gateway_status" {
value = !var.setup_transit_gateway ? module.existing_gateway[0].existing_tg_status : module.transit_gateway[0].new_tg_status
}

// Highly unlikely this is empty or zero, best to throw an error
// Output could be more than one
output "load_balancer_ips" {
value = load_balancer_ips[0]
value = local.load_balancer_ips
}

0 comments on commit 007af2d

Please sign in to comment.