<p>Trying to generate deployments for my helm charts by using this template</p>

<pre><code>{{- range .Values.services }}
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: myapp-{{ . }}
spec:
  replicas: {{ .replicaCount }}
  template:
    metadata:
      labels:
        app: myapp-{{ . }}
        chart: myapp-{{ $.Values.cluster }}-{{ $.Values.environment }}
    spec:
      containers:
      - name: myapp-{{ . }}
        image: {{ $.Values.containerRegistry }}/myapp-{{ . }}:latest
        ports:
        - containerPort: {{ .targetPort }}
        env:
  {{- with .environmentVariables }}
  {{ indent 10 }}
  {{- end }}
      imagePullSecrets:
       - name: myregistry
{{- end }}
</code></pre>

<p>for 2 of my services. In values.yaml I got</p>

<pre><code>environment: dev

cluster: sandbox

ingress:
  enabled: true

containerRegistry: myapp.io

services:
- backend:
    port: 80
    targetPort: 8080
    replicaCount: 1
    environmentVariables:
      - name: SOME_VAR
        value: "hello"
- web:
    port: 80
    targetPort: 8080
    replicaCount: 1
    environmentVariables:
      - name: SOME_VAR
        value: "hello"
</code></pre>

<p>... but the output is not being properly formatted</p>

<pre><code>apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: myapp-map[backend:map[replicaCount:1 targetPort:8080 environmentVariables:[map[name:SOME_VAR value:hello] port:80]]
</code></pre>

<p>instead of</p>

<pre><code>apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: myapp-web
(...)
</code></pre>

<p>and another config</p>

<pre><code>apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: myapp-backend
(...)
</code></pre>

<p>what functions can I use or some different data structure? None of the references (i.e. .environmentVariables are working correctly)</p>

<p>I think you should reconsider the way the data is structured, this would work better:</p>

<pre><code>  services:
  - name: backend
    settings:
      port: 80
      targetPort: 8080
      replicaCount: 1
      environmentVariables:
        - name: SOME_VAR
          value: "hello"

  - name: web
    settings:
      port: 80
      targetPort: 8080
      replicaCount: 1
      environmentVariables:
        - name: SOME_VAR
          value: "hello"
</code></pre>

<p>And your Deployment to look like this:</p>

<pre><code>{{- range .Values.services }}
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: myapp-{{ .name }}
spec:
  replicas: {{ .settings.replicaCount }}
  template:
    metadata:
      labels:
        app: myapp-{{ .name }}
    spec:
      containers:
      - name: myapp-{{ .name }}
        image: {{ $.Values.containerRegistry }}/myapp-{{ .name }}:latest
        ports:
        - containerPort: {{ .settings.targetPort }}
        env:
  {{- with .settings.environmentVariables }}
  {{ toYaml . | trim | indent 6 }}
  {{- end }}
      imagePullSecrets:
       - name: myregistry
{{- end }}
</code></pre>

<p>would actually create two deployments, by adding the <code>---</code> separator.</p>
