spring-cloud/spring-cloud-config

Spring Cloud Config Server - Multi-File Composition / Importing

tomcruise81 opened this issue · 6 comments

Is your feature request related to a problem? Please describe.
I'm trying to group blocks of configuration into individual files for clarity. Unfortunately, I can't find any documentation on if Spring Cloud Config Server offers the ability to reference other Spring Cloud Config Server files from within a given file and have them imported / included in the final rendered file.

Describe the solution you'd like
Much in the same way that Spring Boot offers the spring.config.import option, I'd like to see a way to import or include populated Spring Cloud Config Server files part-a.properties & part-b.properties in template.properties. Maybe name it ${spring.cloud.config.import}

# part-a.properties
property.a=SOME_VALUE_A
# part-b.properties
property.b=SOME_VALUE_B
# template.properties

${spring.cloud.config.import=part-a.properties}

${spring.cloud.config.import=part-b.properties}

Spring Cloud Config Server rendered template.properties:

# template.properties

# part-a.properties
property.a=SOME_VALUE_A

# part-b.properties
property.b=SOME_VALUE_B

Describe alternatives you've considered
Specifying every single property that we want to include is cumbersome and lacks clarity.

Even spring.config.import does not do this, when you use spring.config.import each import statement is still its own property source.

You can have the config server serve up the files in your example by making a request to /part/a,b. In other words if the client had an application name part and activated profiles a, and b, that would cause the config server to return both configuration files in its list of property sources.

Thanks for the input @ryanjbaxter.

One of the benefits of Spring Cloud Config Server is that it doesn't just work with Spring clients but can serve up populated config files directly to be consumed by other types of applications - hence my desire for the rendered result rather than the notion of multiple property sources.

Trying to include the multiple profiles seems to only render the results of the first matching file/profile.

So are you using the config server to serve up specific files? Can you provide an example of the requests you are making to the config server?

https://spring-cloud-config-server.somedomain.com/GIT_PROJECT%28_%29GIT_REPO/PROFILE/BRANCH/template.properties

Where:

  • PROFILE equates to one of our lifecycle environments - dev, val, int, prd
  • BRANCH is the Git branch (we have Spring Cloud Config Server tied to a Bitbucket / Git backend)

Essentially what you are looking for a way to return multiple config files in a single request, correct?

In the simplest sense - yes.

But I could see the benefit to doing something like:

# template.properties

info.app.name=${application.name}
info.app.version=${application.version}

${spring.cloud.config.import=part-a.properties}

${spring.cloud.config.import=part-b.properties}

getting rendered to:

# template.properties

info.app.name=Something Useful
info.app.version=1.2.3.4

# part-a.properties
property.a=SOME_VALUE_A

# part-b.properties
property.b=SOME_VALUE_B

where there's a mix of populated properties and resolved property file contents