I will start with a motivating example of a config that almost represents an envoy proxy config :)
virtual_hosts:
- name: webxp-api_http
domains: ["*"]
routes:
- match: { prefix: "/static/v5.0" }
route: { cluster: bodhi_static }
- match: { prefix: "/"}
route: { cluster: bodhi-web }
clusters:
- name: bodhi_web
- name: bodhi_static
The rule is, that name has to be defined clusters
list have to be defined to be used in the route
part of the config. If you look closely, this config will fail to load, because bodhi_web
is not bodhi-web
. How would I encode that in Dhall?
On one hand I could have clusters
as a list in a let binding, and that would help, but nothig forces me to use the binding and in reality I would like tho think of clusters
as a sum-type for the cluster:
field? Could dependent types help me here (i.e. I remember doing something like this in purescript, that has some limited capacity for dependent type-programming)
Or should I just create a constructor/validator function and abuse assert to get this validated?
Or I just shouldn't? :)
I would approach this by authoring a utility function that generates a correct-by-construction configuration.
Using your example, if we want to ensure that the list underneath the
clusters
field always matches the list of routes, then we derive theclusters
field from theroutes
field: