-2

I need to do a nslookup of the RDS instance address. What is the best way to do this via terraform?

Paolo
  • 21,270
  • 6
  • 38
  • 69
rk123
  • 85
  • 2
  • 12

1 Answers1

0

Use an external data source. Here's a demo which shows how to use a bash script that uses nslookup to retrieve the IP address for google.com.

Given util.sh:

#!/bin/bash
ip=$(nslookup "$1" | awk '/Server/ {print $2}')
jq -n --arg ip "$ip" '{"ip":$ip}'

and main.tf:

locals {
  host = "google.com"
}

data "external" "util" {
  program = ["bash","util.sh","${local.host}"]
}

output "ip" {
  value = data.external.util.result.ip
}
$ terraform apply -auto-approve
ip = "172.30.240.1"
Paolo
  • 21,270
  • 6
  • 38
  • 69