<p>I just started working with ArgoCD and I have an issue I can't find the answer for.</p>
<p>I have a file called <code>clusters.yaml</code> in my Git repo:</p>
<pre><code>clusters:
- name: cluster1-eu-k8s-002
  url: https://cluster1.hcp.northeurope.azmk8s.io:443
  values: 
    nameOverride: ReplaceWithThis
</code></pre>
<p>And I am using the following ApplicationSet in order to deploy Opentelemetry-collector on a bunch of clusters grouped under the label <code>group:dev</code>.</p>
<pre><code>apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: opentelemetry-applicationset
  namespace: argocd
spec:
  generators:
  - git:
      repoURL: git@github.com:removed/cloud.git
      revision: HEAD
      files:
      - path: GitOps/argocd-apps/clusters.yaml
  - clusters:
      selector:
        matchLabels:
          argocd.argoproj.io/secret-type: cluster
          group: dev
  template:
    metadata:
      name: 'opentelemetry-{{name}}'
    spec:
      project: default
      sources:
      - repoURL: https://open-telemetry.github.io/opentelemetry-helm-charts
        chart: opentelemetry-collector
        targetRevision: 0.51.3
        helm:
          valueFiles: 
            - $values/GitOps/argocd-apps/opentelemetry-collector/values/values-dev.yaml
          parameters:
            - name: nameOverride
              value: '{{ index .Clusters.values &quot;nameOverride&quot; }}'
      - repoURL: git@github.com:removed/cloud.git
        ref: values
      destination:
        server: '{{ server }}'
        namespace: opentelemetry
</code></pre>
<p>I am trying to replace a parameter called <code>nameOverride</code> with my value <code>ReplaceWithThis</code> from <code>clusters.yaml</code>.</p>
<p>ArgoCD is not deploying my app because of this line: <code>value: '{{ index .Clusters.values &quot;nameOverride&quot; }}'</code></p>
<p>ArgoCD ApplicationSet controller logs throw some nonsense errors. I am sure I identified the problem correctly, because it works as expected if I just hardcore the string.</p>
<p>What exactly is the issue with the way I am trying to pull that value?</p>

<p>In the <a href="https://argo-cd.readthedocs.io/en/stable/user-guide/application-set/" rel="nofollow noreferrer">Argo CD <code>ApplicationSet</code> controller</a>, you are using <code>{{ index .Clusters.values &quot;nameOverride&quot; }}</code> to access the <code>nameOverride</code> value. However, <code>Clusters</code> is an array in your <code>clusters.yaml</code> file, not a dictionary. So, you should not be trying to directly index it as if it is a dictionary. (In YAML, an array (or list) is denoted by items beginning with a dash (<code>-</code>).)</p>
<p>The <code>.Clusters</code> field will contain an <em>array</em> of clusters from your <code>clusters.yaml</code> file, and you want to access the <code>values.nameOverride</code> field of each cluster. However, your current syntax is treating <code>Clusters</code> as if it were a dictionary that can be indexed directly with <code>.values</code>.</p>
<p>You should instead iterate over the <code>Clusters</code> array to access each <code>values</code> dictionary individually. You may need to use a loop structure to do this, or modify your configuration so that <code>values</code> is not nested within an array.</p>
<p>You can also use a different structure for your <code>clusters.yaml</code> file.<br />
If you only have one cluster, you could structure your <code>clusters.yaml</code> file like this:</p>
<pre class="lang-yaml prettyprint-override"><code>clusters:
  name: cluster1-eu-k8s-002
  url: https://cluster1.hcp.northeurope.azmk8s.io:443
  values: 
    nameOverride: ReplaceWithThis
</code></pre>
<p><em>Then</em>, in this case, you can directly access <code>nameOverride</code> with <code>{{ index .Clusters.values &quot;nameOverride&quot; }}</code>.</p>
<p>If you have multiple clusters and need a unique <code>nameOverride</code> for each, you could create a separate file for each cluster in your repository and adjust the <code>files</code> field in your <code>ApplicationSet</code> to match the new file structure.</p>
<p>That would be how a <a href="https://argocd-applicationset.readthedocs.io/en/stable/Generators-Git/#git-generator-files" rel="nofollow noreferrer">Git file generator</a> would be able to read each of those files, and access the <code>values.nameOverride</code> field of each cluster in their respective file.</p>
