Last active
March 23, 2021 17:28
-
-
Save ImIOImI/bab6846b8e89e1c79624a8bd632af2fe to your computer and use it in GitHub Desktop.
Get the address for an NGINX ingress controller's load balancer and create a route53 address for it.
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
resource "local_file" "get-ingress" { | |
content = <<EOF | |
$info=kubectl describe svc ingress-nginx-controller -n ingress-nginx | |
$string = $false | |
foreach($line in $info) { | |
if ($line -like "LoadBalancer Ingress:*") { | |
$string = $line -replace "LoadBalancer Ingress:", "" | |
$string=$string.trim() | |
break | |
} | |
} | |
Write-Output "{ ""elb"" : ""$string""}" | |
EOF | |
filename = "${path.module}/get-ingress.ps1" | |
} | |
data "external" "get-ingress" { | |
program = ["Powershell.exe", local_file.get-ingress.filename] | |
query = {} | |
} | |
resource "aws_route53_record" "url" { | |
zone_id = <r53 zone id> | |
name = <subdomain name> | |
type = "A" | |
alias { | |
evaluate_target_health = false | |
name = data.external.get-ingress.result.elb | |
zone_id = <elb zone> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment