geofffranks / spruce

A BOSH template merge tool
MIT License
433 stars 78 forks source link

Question regarding using env vars in yaml paths #359

Closed kitsirota closed 1 year ago

kitsirota commented 2 years ago

Hello @geofffranks and @jhunt,

Hope all is well!

We are using spruce in our manifest build system and during the most recent refactor we hit a use case that I . We're running a bash script that is grabbing key names using yq to build a list of manifests we need to build and it would be really great if we could use env vars as part of the path in the spruce grab/concat operators.

For example, given two yaml files:

#Deployment configs
---
deployment-definitions:
  first-app:
    package_name: first-app-api
    namespace: foo
    ...
  second-app:
    package_name: second-app-ui
    namespace: bar
    ...

We're creating a list of the apps in the definition file and for each loop we set the app name as an env var. first-app second-app

Now on the manifest template side, we would like to plug in the values as env vars in the path so we can generate all the deployment manifests from a generic deployment template.

#Deployment template example
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: (( concat deployment-definitions.$APP_NAME.package_name "-deployment" ))
  namespace: (( grab deployment-definitions.$APP_NAME.namespace ))

Is there a way to do something like this with spruce?

Thank you!

geofffranks commented 2 years ago

I don't believe that's something you can do currently, but if you want to PR it, I'm totally up for merging and releasing it!

TurbulentCupcake commented 1 year ago

@geofffranks Here's a PR to resolve the issue: https://github.com/geofffranks/spruce/pull/378 CC: @kitsirota

kitsirota commented 1 year ago

Thank you so much @TurbulentCupcake and @geofffranks!