As part of my automation pipeline, I wanted to automatically create a few A records in Cloudflare that point to my AKS kubernetes cluster. I was creating the records using Terraform. Unfortuantely, at the time of writing, the azurerm
provider for Terraform does not have a data source for load balancers.
Instead, I could use a PowerShell script to find the public IP address, and then pass the value in as a variable to my Terraform. Things are a bit more complicated if your load balancer has multiple IP addresses assigned (as is the case if you specify --outbound-type loadbalancer
when creating your AKS cluster) as you must lookup the correct IP address. See Using SNAT for outbound connections for more information.
Here’s the script:
1 | $resource_group = "aks-resource-group-here" |
Here’s an example of calling the terraform:
1 | terraform apply -var "public_ip_address=$public_ip_address" |
Another option to consider is using something like ExternalDNS, so DNS records will be created automatically based on the ingress resources in my kubernetes cluster.
It you know of a better way to do this - please do let me know!