This PR is auto-generated from #13039 to be assessed for backporting due to the inclusion of the label backport/1.11.x.
The below text is copied from the body of the original PR.
The logic for evaluating local variables used to rely on their definition order, with some edge cases.
Typically locals blocks define multiple local variables, which don't necessarily appear in the same order at evaluation as within the template, leading to inconsistent behaviour, as the order in which those are added to the list of local variables is non-deterministic.
To avoid this problem, we change how local variables are evaluated, and we're adopting a workflow similar to datasources, where the local variables first build a list of direct dependencies.
Then when evaluation happens, we evaluate all the dependencies recursively for each local variable, which takes care of this issue.
As with Datasources, we add a cap to the recursion: 10. I.e. if the evaluation of a single variable provokes an infinite recursion, we stop at that point and return an error to the user, telling them to fix their template.
Backport
This PR is auto-generated from #13039 to be assessed for backporting due to the inclusion of the label backport/1.11.x.
The below text is copied from the body of the original PR.
The logic for evaluating local variables used to rely on their definition order, with some edge cases. Typically
locals
blocks define multiple local variables, which don't necessarily appear in the same order at evaluation as within the template, leading to inconsistent behaviour, as the order in which those are added to the list of local variables is non-deterministic.To avoid this problem, we change how local variables are evaluated, and we're adopting a workflow similar to datasources, where the local variables first build a list of direct dependencies. Then when evaluation happens, we evaluate all the dependencies recursively for each local variable, which takes care of this issue.
As with Datasources, we add a cap to the recursion: 10. I.e. if the evaluation of a single variable provokes an infinite recursion, we stop at that point and return an error to the user, telling them to fix their template.
Closes: #13018
Overview of commits
- e6720abf670d44922d78655611e259b15159fa3f - f80019385034406af7d818c44d8dd7c039e27e9d - 38d19f695628c22871bb2df23fe4cfc125d00b41 - 4f54212560156c454de0edc1c2740797e7ef88f6 - 3b9d3845c31b5db25ffe5022314246e6210c13f4 - 3f114ce5af1c00855f735a831413d5ad2a9342fb - 68bc732c47fed4788f2ee46e73b443d62459bf75 - 8c134ba900a019a9ff89b0fc21c9441a4de95d26 - 7823d159aff5a4a713a82c1ad537963a9bacfc92