Example yaml config generator using m4 macros --------------------------------------------- The idea here is to make nicely named macros expanding chunks of common configuration in order to make shorter, more expressive top-level configurations. It can also cut down on the duplication in projects where lots of large yaml files with similar content required. It is inspired by the Google SRE workbook essays on configuration [1] [2]. Given the lightweight nature of this approach coupled with the ubiquity of m4, it strikes a nice balance when running it over the "configuration pitfalls" outlined in [2]. The article in [2] presents "jsonnet" [3] as an answer to these pitfalls. It is also worth noting that this prototype is essentially the same approach as that of autoconf [4], which shows that it scales. The top-level config to be maintained by administrators is captured in `my_config.yaml.m4'. The resulting `my_config.yaml' configuration can be generated by applying the macros in the correct order: $ m4 -P 0*.m4 my_config.yaml.m4 >my_config.yaml The filenames should ensure that the library macros are loaded first. The `-P' option is important as it prefixes all builtins with `m4_' in order to reduce the probability of unwanted expansions. Note that we redefine the default quotes (` and ') to be inline with autoconf ([ and ]), as it is arguably more readable and avoids some other issues [3]. [1] https://landing.google.com/sre/workbook/chapters/configuration-design/ [2] https://landing.google.com/sre/workbook/chapters/configuration-specifics/ [3] https://jsonnet.org [4] https://www.gnu.org/software/autoconf/manual/autoconf.html#Introduction [5] https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Changequote-is-Evil.html
mikey-austin/yaml_config_macros
Example project illustrating the use of m4 macros to simplify yaml configs
M4