I'd like to write code like below in jsonnet. Can jsonnet support this?
local region = `curl http://100.100.100.200/latest/metadata/region_id`
the region
variable should be the output of executing curl http://100.100.100.200/latest/metadata/region_id
.
It's not possible to call external commands from within Jsonnet. This is by design (see Hermeticity https://jsonnet.org/articles/design.html).
It's necessary to explicitly pass data to Jsonnet. There are three mechanisms for that:
1)
import
/importstr
which is the best for static things that live alongside the code. But you can use them in other ways (see Kerndog73's answer).2) External variables - global parameters that are available in the whole program e.g.:
3) Top-level arguments - if your jsonnet program evaluates to a function, you can pass arguments to it:
If you are using ksonnet it may be different, because ksonnet has its own mechanisms for passing data to jsonnet AFAIK.