Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document unsupported "bracket-less" collection addressing #3412

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading