Using go template with Kots and kustomize

Hello There,
We would like to add a block of code based on if condition. Something like we want to add a bunch of annotations only for cloud deployments like below.

apiVersion: v1
kind: Service
metadata:
  {{repl if not IsKurl}}
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-backend-protocol: tcp
    service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled: 'true'
    service.beta.kubernetes.io/aws-load-balancer-type: nlb
  {{repl end}}
  labels:
    helm.sh/chart: ingress-nginx-3.30.0
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/version: 0.46.0
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: controller
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  type: "{{repl ternary NodePort LoadBalancer IsKurl}}"
  ports:
    - name: http
      nodePort: 80
      port: 80
      protocol: TCP
      targetPort: http
    - name: https
      nodePort: 443
      port: 443
      protocol: TCP
      targetPort: https
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/component: controller

When we tried doing that and used kustomize to build it throws validation errors. yaml: line 5: mapping values are not allowed in this context'.
Is there a way of making this work so that we can leverage the use of kots templte functions?

Did you ever determine a solution to this question?

Hey Mike - I am sorry you did not get a reply. In your case, I would define separate yamls, like a aws-service.yaml, a gke-service.yaml, etc… and then you could use the ‘kots.io/when’ label annotation to only deploy the correct yaml based on the cloud provider.

For example you could have a config option that the user selects which cloud environment they are deploying to, and then based on the selection, deploy the corresponding manifest I.e., if they select ‘aws’, then you deploy the ‘aws-ingress.yaml’.

Here is an example of a service for postgres that only gets deployed if the config option is set to use ‘embedded postgres’ vs ‘external postgres’

Here is the documenation on how to optionally deploy a service Including Optional and Conditional Resources | Replicated Docs