How to get Pod IP for use in config of another pod on k8s?

I need to grab the assigned IP address of a created Pod or Deployment for use in the Config part of another Pod/Deployment. How do you do this with Terraform? The command to get a Pod’s IP is pretty simple ($ kubectl get pod mypod-6bbf4f8985-ntd86 -o=json | jq .status.podIP) …is there a way to run this on the remote k8s cluster and stuff the answer into an env var or Terraform output??

I think this is more of a k8s question. Ideally you shouldn’t be using Pod IP addresses like this as pods can be recreated due to various reasons. I think it’s best to use a k8s service (A cluster IP service should be suitable for this case) infront of the first pod and you can use the second pod config to use the cluster IP.
With that kind of design your second pod will be fail proof even if first pod gets recreated.