happytal / substitute-variables

Azure DevOps task for substituting variables in plain JSON and YAML files
MIT License
1 stars 0 forks source link

What happens to multi-object templates? #5

Closed artisticcheese closed 3 years ago

artisticcheese commented 3 years ago

Hello,

What would happen with file like below

apiVersion: v1
kind: Service
spec:
  type: LoadBalancer
  selector:
    app: esb-api
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: esb-api
  namespace: dev
fhervieux commented 3 years ago

Hi,

Right now this will fail. There is no handling of multi document files. What can be done easily is handling them as we would handle two different files. Each document of the file will have its fields substituted as if it were in a separate file, then then file is written back as a multi document YAML file. This seems to be the most straight forward. The only thing to keep in mind is that you will not be able to substitute a different value for each document:

for your input and the variable metadata.name=foo you will end up with

apiVersion: v1
kind: Service
spec:
  type: LoadBalancer
  selector:
    app: esb-api
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: foo
  namespace: dev

and with the variable kind=foo you will end up with

apiVersion: v1
kind: foo
spec:
  type: LoadBalancer
  selector:
    app: esb-api
---
apiVersion: apps/v1
kind: foo
metadata:
  name: esb-api
  namespace: dev

I just tried it and it worked so if you are fine with that I can deploy it to Azure DevOps.

artisticcheese commented 3 years ago

Yes, looks like good solution

fhervieux commented 3 years ago

It is published as version 1.1.0 to Azure DevOps.