# Argo CD ApplicationSet — list generator stamps out one Application per environment
# from a single template. The {{env}} substitution selects the matching values overlay.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: orders
  namespace: argocd
spec:
  goTemplate: true
  goTemplateOptions: ["missingkey=error"]
  generators:
    - list:
        elements:
          - env: dev
          - env: staging
          - env: prod
  template:
    metadata:
      name: 'orders-{{.env}}'
    spec:
      project: default
      destination:
        server: https://kubernetes.default.svc
        namespace: 'orders-{{.env}}'
      sources:
        - repoURL: ghcr.io/purisev
          chart: universal-helm-chart
          targetRevision: 3.3.0
          helm:
            releaseName: 'orders-{{.env}}'
            valueFiles:
              - $values/docs/02-examples/09-multi-env-overrides/values-base.yaml
              - $values/docs/02-examples/09-multi-env-overrides/values-{{.env}}.yaml
        - repoURL: https://github.com/purisev/universal-helm-chart.git
          targetRevision: v3.3.0
          ref: values
      syncPolicy:
        automated:
          prune: true
          selfHeal: true
        syncOptions:
          - CreateNamespace=true
          - ServerSideApply=true
