Idea: Add per-environment global variables #18

Closed
kydorn opened this Issue May 4, 2016 · 8 comments

Projects

None yet

2 participants

@kydorn
kydorn commented May 4, 2016

It would add a lot of flexibility being able to specify global environment variables, that apply only to a specific environment, but to all templates.

Like any other global variable, it could be overriden by template-specific variables.

@markround
Owner

Hi, Thanks for the suggestion. Do you have an example for how you'd like to see it working ?

@kydorn
kydorn commented May 4, 2016 edited

Sure, for example:

data_sources: [ 'defaults', 'file' ]
template_sources: [ 'file' ]
defaults:
    global:
      variable: 'default value'
    template.erb:
       ...
    template2.erb:
       ...
environments:
    development:
      global: 
        variable: 'default value for development environment'
      template.erb
         variable: 'local value for template.erb'
    staging:
      global: 
        variable: 'default value for staging environment'
    production:
     ...

This is specially useful when we are sharing the same variable between multiple templates and different environments. If we need the same variable to be consistent in an environment, we currently have to define it for each template that uses it (and for each environment)

@markround
Owner

Right, I see. Let me have a think about this, and I'll see if I can add something like that for you.

@markround
Owner
markround commented May 5, 2016 edited

Just committed b24073d , which I think will do what you're after. Take a look at the test fixtures:

And the tests themselves, which show the expected output : https://github.com/markround/tiller/blob/feature/per_env_global/features/file_globals.feature

It looks pretty much like what you were after. It was a very simple change, I just made the file datasource pick up a new global_values: block, and you can also use the defaults datasource to specify a default.

Is this OK for you ?

@kydorn
kydorn commented May 5, 2016

Yup, that would do the trick! Thank you so much for this fast response :)

@markround
Owner

Great :) OK, I'll add some notes to the documentation, tidy it up a bit and get a release out ASAP (probably tomorrow). I'll give due credit for the suggestion in the Changelog, would you like me to reference your GitHub ID/website/blog/whatever ?

@kydorn
kydorn commented May 5, 2016

You could use the handler if you want, but there is no need. I'm actually using Tiller at work for creating a hierarchical configuration for docker containers and I just was too lazy to learn ruby and change it myself. Thank you so much for your work!

@markround
Owner

Resolved by v0.7.7. An updated gem will be built and released shortly. Thanks again for the suggestion!

@markround markround closed this May 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment