<p>I have the following data in my function $newdict</p>
<pre><code>   modules:
     module1: 
      enabled: true
     module2:
      enabled: false
     module3:
      enabled: true, etc
</code></pre>
<p>What is need to do is : check if module1 enabled, then set enabled for module2 as well. What I tried in _helpers.tpl file:</p>
<pre><code>  {{- range $key, $value := $newdict -}}
  {{ if and (eq $key &quot;module1&quot;) (eq &quot;enabled&quot; &quot;true&quot;) }}
  {{ $_ := set $newdict $key &quot;module2&quot; (eq &quot;enabled&quot; &quot;true&quot;) }} 
  {{ end }}  
  {{ end }}
  {{ toYaml $newdict }}
</code></pre>
<p>helm lint doesn't show any errors, but the changes are not reflected in $newdict</p>
<p>This thing is needed for deployment.yaml to deploy init container:</p>
<pre><code>     initContainers:
  {{- $mycustom := (include &quot;myfunction&quot; . ) | fromYaml}}
  {{- range $key, $value := $mycustom }}
    {{- if $value.enabled }}
    - name: init-{{ $key }}-myinit
</code></pre>
<p>So, in the end, I need to deploy init container &quot;module2&quot; only if &quot;module1&quot; is also deployed</p>

user15824359
<p>Helm's general style is that values are immutable.  I'd avoid the <code>set</code> function here and stick to a more functional style.</p>
<p>It may help your setup that you can directly index things in dict (map) structures, or use the standard Go template <code>index</code> function.  You don't need to iterate through the entire dict looking for a key.  So if you're sure the variable has keys <code>module1</code> and <code>module2</code> then you can simplify the final logic to:</p>
<pre class="lang-yaml prettyprint-override"><code>initContainers:
{{- if or .Values.module1.enabled .Values.module2.enabled }}
  - name: init-module2-myinit
  ...
{{- end }}
</code></pre>
<p>Your setup hints at having more init containers; <code>module1</code>, <code>module2</code>, and <code>module3</code> would each have their own init containers, but you also want to emit <code>module2</code>'s whenever <code>module1</code> is turned on regardless of the <code>module2</code> setting.  One way to approach this might be to write a helper function that decided whether a given module was enabled:</p>
<pre class="lang-none prettyprint-override"><code>{{/* Decide whether some module is enabled.  Call with a list of
     two items, the values structure to examine and the specific
     module key.  Returns either the string &quot;true&quot; or an empty
     string. */}}
{{- define &quot;is-module-enabled&quot; -}}
{{- $modules := index . 0 -}}
{{- $key := index . 1 -}}
{{- if index $modules $key &quot;enabled&quot; -}}
true
{{- else if and (eq $key &quot;module2&quot;) $modules.module1.enabled -}}
true
{{- end -}}
{{- end -}}
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>initContainers:
{{- range $key := .Values.modules -}}
{{- if include &quot;is-module-enabled&quot; (list .Values.modules $key) }}
  - name: init-{{ $key }}-myinit
  ...
{{- end }}
{{- end }}
</code></pre>
