Skip to content

Commit

Permalink
Add istio ingress lb to outputs for use in dns creation
Browse files Browse the repository at this point in the history
  • Loading branch information
mcgin314 committed Oct 8, 2024
1 parent cf605d6 commit 75cbec8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
15 changes: 15 additions & 0 deletions load_balancer_dns.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# Script to get Load Balancer DNS Name based on the tag Name

LB_NAME=$1

lb_arn=$(for i in $(aws elbv2 describe-load-balancers --query 'LoadBalancers[].LoadBalancerArn' --output text); \
do aws elbv2 describe-tags --resource-arns "$i" --query "TagDescriptions[?Tags[?Key=='Name' &&Value=='$LB_NAME']].ResourceArn" --output text ;done)

if [ -z "$lb_arn" ]; then
lb_arn="no_arn_exists_for_this_lb_name"
fi

dns_name=$(aws elbv2 describe-load-balancers --load-balancer-arns $lb_arn --query 'LoadBalancers[].DNSName' --output text)

jq -n --arg dnsName "$dns_name" '{"dnsName":$dnsName}'
20 changes: 13 additions & 7 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ resource "kubernetes_namespace" "ns" {
}
}

# data "kubernetes_service" "apiserver" {
# metadata {
# name = "kubernetes"
# }
# }

resource "helm_release" "base" {
depends_on = [module.images]
chart = "base"
Expand Down Expand Up @@ -111,7 +105,6 @@ resource "helm_release" "istiod" {
set {
name = "globalproxy.excludeIPRanges"
value = "${var.kubernetes_service_apiserver}/32"
# value = "${data.kubernetes_service.apiserver.spec[0].cluster_ip}/32"
}
}

Expand Down Expand Up @@ -194,3 +187,16 @@ resource "helm_release" "egress" {

timeout = 90
}

###################################################################
# INGRESS NLB DATA
###################################################################

# We need to lookup the DNS entry for the istio ingress load balancer
# This value is used to create the CNAME record for cluster app/api addressing in the DNS module
# We use this external data source to avoid issues with running plans
data "external" "load_balancer_dns" {
depends_on = [helm_release.ingress]

program = ["bash", "${path.module}/load_balancer_dns.sh", format("%v-%v", var.cluster_name, "istio-ingress")]
}
5 changes: 5 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ output "module_version" {
description = "The version of this module."
value = local.module_version
}

output "istio_ingress_lb" {
description = "The Istio ingress network load balancer."
value = data.external.load_balancer_dns.result.dnsName
}

0 comments on commit 75cbec8

Please sign in to comment.