Cue generate Yaml Configs #1266
-
In our project, we use go template to generate yaml configs. An example of our yaml template:
'global' function looks for a value along the path in the global map[string]interface{} Variable values are located in the variable.yaml file:
I would like to use cuelang, since the go template is too weak a tool for generating configs.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I would use the following patterns, given you want to maintain the variables as Yaml. My personal preference would be to convert all inputs to CUE.
// schemas
#Global: {
host: string
}
#Mode: {
user: string
}
// yaml vars validation
global: #Global
mode: [env=string]: #Mode
// "flags" for controlling selection
#env: string | *"dev" @tag(env)
// output mapping, uses the current "function" syntax for CUE
#Output: {
// defines a top level input value, could have them individually
#IN: {
global: #Global
vars: #Mode
}
// the result is where the actual mapping happens
result: {
login: "\(#IN.vars.user)@\(#IN.global.host)"
}
}
// "calling" the mapping with concrete inputs
final: (#Output & { #IN:{ "global": global, vars: mode[#env]} }).result
global:
host: domain.com
mode:
dev:
user: "dev"
prd:
user: "prd"
login: "[email protected]"
login: "[email protected]" things to note:
|
Beta Was this translation helpful? Give feedback.
I would use the following patterns, given you want to maintain the variables as Yaml. My personal preference would be to convert all inputs to CUE.
main.cue