<p>I am trying to create a helm template for Istio's ServiceEntry which has a list of  addresses for static ip addresses. In values.yaml, I have</p>
<pre><code>- name: test-se
  namespace: test-se-ns
  egressUrls: 
  - mydbhost.com
  port: 32306
  protocol: TCP
  ipAddress: 10.2.2.2
</code></pre>
<p>In the .tpl file I am trying to add the value of ipAddress to a list</p>
<pre><code>  {{- with .ipAddress }}
  addresses: 
  - {{ .ipAddress | quote }}
  {{- end }}
</code></pre>
<p>Always fails with exception</p>
<p>templates/_service_entry.tpl:18:13: executing &quot;common.serviceentry.tpl&quot; at &lt;.ipAddress&gt;: can't evaluate field ipAddress in type string</p>
<p>Any idea what I am doing wrong?</p>

Upen
<p>If you use <code>with</code> you make the thing that you have used as <code>with</code> the context inside that block.</p>
<p>So, use the dot to refer to it.</p>
<pre class="lang-yaml prettyprint-override"><code>{{- with .ipAddress }}
addresses: 
  - {{ . | quote }}
{{- end }}
</code></pre>
<p>From the <a href="https://pkg.go.dev/text/template" rel="nofollow noreferrer">docs</a>:</p>
<pre><code>{{with pipeline}} T1 {{end}}
    If the value of the pipeline is empty, no output is generated;
    otherwise, dot is set to the value of the pipeline and T1 is
    executed.
</code></pre>
<hr />
<p>In this case, an <code>if</code> seems also fitting, since you do not much with the new context.</p>
<pre class="lang-yaml prettyprint-override"><code>{{- if .ipAddress }}
addresses: 
  - {{ .ipAddress | quote }}
{{- end }}
</code></pre>
