Skip to content

Commit

Permalink
Retrieve load balancer dns
Browse files Browse the repository at this point in the history
  • Loading branch information
mcgin314 committed Oct 7, 2024
1 parent d6fea96 commit 885b8f8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions aws_data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ data "aws_vpc" "dummy_vpc" {
values = ["vpc0-dummy"]
}
}

# We need to lookup the DNS entry for the istio ingress load balancer created by the tfmod-istio
# We then use this value to create the CNAME record for cluster app/api addressing
data "external" "load_balancer_dns" {
program = ["bash", "${path.module}/load_balancer_dns.sh", format("%v-%v", var.cluster_name, "istio-ingress")]
}

# format("%v-%v", var.cluster_name, "metrics-server")
output "load_balancer_dns" {
value = data.external.load_balancer_dns.result.dnsName
}
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}'

0 comments on commit 885b8f8

Please sign in to comment.