diff --git a/load_balancer_dns.sh b/load_balancer_dns.sh new file mode 100755 index 0000000..744a801 --- /dev/null +++ b/load_balancer_dns.sh @@ -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}' \ No newline at end of file diff --git a/main.tf b/main.tf index 8a73964..5d7f8f9 100644 --- a/main.tf +++ b/main.tf @@ -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" @@ -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" } } @@ -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")] +} \ No newline at end of file diff --git a/outputs.tf b/outputs.tf index b999ac9..ef947c9 100644 --- a/outputs.tf +++ b/outputs.tf @@ -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 +} \ No newline at end of file