<p>I'm using Terraform <code>helm_release</code> resource to install <code>bitnami/redis</code> instance in my K8s cluster.</p>
<p>The code looks like this:</p>
<pre class="lang-js prettyprint-override"><code>resource &quot;helm_release&quot; &quot;redis-chart&quot; {
  name = &quot;redis-${var.env}&quot;

  repository = &quot;https://charts.bitnami.com/bitnami&quot;
  chart      = &quot;redis&quot;
  namespace  = &quot;redis&quot;
  create_namespace = true

  set {
    name  = &quot;auth.enabled&quot;
    value = &quot;false&quot;
  }

  set {
    name  = &quot;master.containerPort&quot;
    value = &quot;6379&quot;
  }

  set {
    name  = &quot;replica.replicaCount&quot;
    value = &quot;2&quot;
  }
}
</code></pre>
<p>It completes successfully and in a separate directory I have my <code>app</code> terraform configuration.
In the <code>app</code> configuration, I want to get get the redis host from the above <code>helm_release</code>.</p>
<p>I'm doing it like this:</p>
<pre class="lang-js prettyprint-override"><code>data &quot;kubernetes_service&quot; &quot;redis-master&quot; {
  metadata {
    name      = &quot;redis-${var.env}-master&quot;
    namespace = &quot;redis&quot;
  }
}
</code></pre>
<p>And then in the <code>kubernetes_secret</code> resource I'm passing the data to my <code>app</code> deployment:</p>
<pre class="lang-js prettyprint-override"><code>resource &quot;kubernetes_secret&quot; &quot;questo-server-secrets&quot; {
  metadata {
    name      = &quot;questo-server-secrets-${var.env}&quot;
    namespace = kubernetes_namespace.app-namespace.metadata.0.name
  }

  data = {
    REDIS_HOST            = data.kubernetes_service.redis-master.metadata.0.name
    REDIS_PORT            = data.kubernetes_service.redis-master.spec.0.port.0.port
  }
}
</code></pre>
<p>But unfortunately, when I run the app <code>deployment</code> I'm getting the following logs:</p>
<blockquote>
<p>[ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND
redis-dev-master
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26) [ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND</p>
</blockquote>
<p>Which suggests that <code>redis-dev-master</code> is not a correct host for the <code>redis</code> instance.</p>
<p>How do I get the <code>redis</code> host from <code>helm_release</code> or any underlying services the <code>release</code> creates?</p>
<p>I've tried debugging and <code>pinging</code> a specific pod from my <code>app</code> deployment.</p>
<p>For reference, these are my <code>redis</code> resources:</p>
<pre><code>NAME                       READY   STATUS    RESTARTS   AGE
pod/redis-dev-master-0     1/1     Running   0          34m
pod/redis-dev-replicas-0   1/1     Running   1          34m
pod/redis-dev-replicas-1   1/1     Running   0          32m

NAME                         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service/redis-dev-headless   ClusterIP   None             &lt;none&gt;        6379/TCP   34m
service/redis-dev-master     ClusterIP   172.20.215.60    &lt;none&gt;        6379/TCP   34m
service/redis-dev-replicas   ClusterIP   172.20.117.134   &lt;none&gt;        6379/TCP   34m

NAME                                  READY   AGE
statefulset.apps/redis-dev-master     1/1     34m
statefulset.apps/redis-dev-replicas   2/2     34m
</code></pre>

matewilk
<p>Maybe you were just using the wrong <code>attribute</code> to get that information. Checking the documentation at the <a href="https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/data-sources/service" rel="nofollow noreferrer">Terraform Registry Website</a> we can use the
<code>cluster_ip</code> attribute as described at the <a href="https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/data-sources/service#spec" rel="nofollow noreferrer">spec</a> documentation description.
So you should end up with something like:</p>
<pre><code>data.kubernetes_service.redis-master.spec.cluster_ip
</code></pre>
<p>And finally ending up with the following:</p>
<pre><code>resource &quot;kubernetes_secret&quot; &quot;questo-server-secrets&quot; {
  metadata {
    name      = &quot;questo-server-secrets-${var.env}&quot;
    namespace = kubernetes_namespace.app-namespace.metadata.0.name
  }

  data = {
     REDIS_HOST            = data.kubernetes_service.redis-master.spec.cluster_ip
     REDIS_PORT            = data.kubernetes_service.redis-master.spec.port
  }
}
</code></pre>
