Description
Description
Given a bake file with
variable "FOO" {
default = ["one", "two"]
}
there is currently no way to override FOO
via environment variable. Being able to override lists of strings or numbers would very valuable, especially when these lists are used to build up a matrix (which itself cannot be overridden).
Other users have posted similar questions (#2882, #2398 (comment)) with creative workarounds, but those only work when you are in control of the file. In my case, an external project has published their own bake file, but I cannot currently take advantage of it (directly calling it remotely) due to not being able to override their list-based variables.
I looked into the error to ensure I wasn't simply doing something wrong and saw this TODO:
buildx/bake/hclparser/hclparser.go
Lines 320 to 321 in 2eaea64
I took a stab at implementing it, but came across issues that made me think it better to create an issue before submitting an actual PR. They all boil down to issues of typing and exactly what you want to support. Despite the code comment, there was only one (atypical) scenario where I was able to actually make a true list (same typed elements). Even in my example above, that is considered a tuple, which just happens to have members which are all strings. The only way I was able to produce a true list was by by using a function that returns an actual list, e.g.
variable "FOO" {
default = split(",", "one,two")
}
To limit the complexity, I made some assumptions:
- Any tuple type (the common case) needs members all of the same type. This means that variables with a default of
[]
cannot be overridden (since there is no defined type and the intended usage is unknown). - Sets were omitted, not because they're problematic, but I assumed they wouldn't actually occur.
- Objects/Maps remain unsupported
- These lists/tuples would contain only primitive values
If you're still open to this feature, I'd be happy to create a PR.