Skip to content

Commit

Permalink
Document unsupported "bracket-less" collection addressing
Browse files Browse the repository at this point in the history
  • Loading branch information
mr0re1 committed Dec 16, 2024
1 parent 49db0d3 commit b8f37f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,10 @@ To learn more about how to refer to a module in a blueprint file, please consult
Variables can be used to refer both to values defined elsewhere in the blueprint
and to the output and structure of other modules.

> [!NOTE]
> "Brackets-less" access to elements of collection is not supported, use brackets.
> E.g. `pink.lime[0].salmon` instead of `pink.lime.0.salmon`.

### Blueprint expressions

Expressions in a blueprint file can refer to deployment variables or the outputs
Expand Down
8 changes: 8 additions & 0 deletions pkg/config/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ func bpTraversalToTerraform(t hcl.Traversal) (hcl.Traversal, error) {

// BlueprintExpressionLiteralToExpression takes a content of `$(...)`-literal and transforms it to `Expression`
func BlueprintExpressionLiteralToExpression(s string) (Expression, error) {
// TODO: FIX: this function relies on assumption that
// `epxrToTokens(toExpression(tokenize(X))) == tokenize(X)`
// This is not correct, e.g.:
// ```
// epxrToTokens(toExpression(tokenize("pink.lime.0.salmon"))) ==
// tokenize("pink.lime[0].salmon") != tokenize("pink.lime.0.salmon")
// ```
// As a result `pink.lime.0.salmon` can not be properly translated.
bpExp, diag := hclsyntax.ParseExpression([]byte(s), "", hcl.Pos{})
if diag.HasErrors() {
return nil, diag
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func TestParseBpLit(t *testing.T) {
{"$(vars.green.sleeve)", "var.green.sleeve", false},
{`$(vars.green["sleeve"])`, `var.green["sleeve"]`, false},
{"$(vars.green.sleeve[3])", "var.green.sleeve[3]", false},
{"$(vars.green[3].sleeve)", "var.green[3].sleeve", false},

{"$(var.green)", "module.var.green", false},
{"$(box.green)", "module.box.green", false},
Expand Down Expand Up @@ -135,6 +136,9 @@ echo "Hello $(vars.project_id)"
{"$(vars[3]])", "", true}, // can't index vars
{`$(vars["green"])`, "", true}, // can't index module

// TODO: uncomment
// see comment to `BlueprintExpressionLiteralToExpression`
// {"$(pink.lime.0.salmon)", "module.pink.lime[0].salmon", false},
}
for _, tc := range tests {
t.Run(tc.input, func(t *testing.T) {
Expand Down

0 comments on commit b8f37f4

Please sign in to comment.