diff --git a/ast/environment_test.go b/ast/environment_test.go index 09a27e18..9eff5e13 100644 --- a/ast/environment_test.go +++ b/ast/environment_test.go @@ -13,7 +13,10 @@ import ( "github.com/pulumi/esc/syntax/encoding" ) -const example = ` +func TestExample(t *testing.T) { + t.Parallel() + + const example = ` imports: - green-channel - us-west-2 @@ -30,9 +33,33 @@ config: environment: prod ` -func TestExample(t *testing.T) { + syntax, diags := encoding.DecodeYAML("", yaml.NewDecoder(strings.NewReader(example)), nil) + require.Len(t, diags, 0) + + environment, diags := ParseEnvironment([]byte(example), syntax) + assert.Len(t, diags, 0) + + assert.Nil(t, environment.Description) +} + +func TestExample2(t *testing.T) { t.Parallel() + const example = ` +imports: + - green-channel + - us-west-2 +config: + aws: + fn::open::aws-oidc: + sessionName: site-prod-session + roleArn: some-role-arn + pulumi: + aws:defaultTags: + tags: + environment: prod +` + syntax, diags := encoding.DecodeYAML("", yaml.NewDecoder(strings.NewReader(example)), nil) require.Len(t, diags, 0) diff --git a/ast/expr.go b/ast/expr.go index 40b99a92..3cca8505 100644 --- a/ast/expr.go +++ b/ast/expr.go @@ -531,6 +531,11 @@ func tryParseFunction(node *syntax.ObjectNode) (Expr, syntax.Diagnostics, bool) case "fn::toString": parse = parseToString default: + if strings.HasPrefix(kvp.Key.Value(), "fn::open::") { + parse = parseShortOpen + break + } + if strings.HasPrefix(strings.ToLower(kvp.Key.Value()), "fn::") { diags = append(diags, syntax.Warning(kvp.Key.Syntax().Range(), "'fn::' is a reserved prefix", @@ -604,6 +609,18 @@ func parseOpen(node *syntax.ObjectNode, name *StringExpr, args Expr) (Expr, synt return OpenSyntax(node, name, obj, provider, inputs), diags } +func parseShortOpen(node *syntax.ObjectNode, name *StringExpr, args Expr) (Expr, syntax.Diagnostics) { + kvp := node.Index(0) + provider := strings.TrimPrefix(kvp.Key.Value(), "fn::open::") + inputs, ok := args.(*ObjectExpr) + if !ok { + return nil, syntax.Diagnostics{ExprError(args, fmt.Sprintf("the argument to fn::open::%s must be an object", provider), "")} + } + p := name.Syntax().(*syntax.StringNode) + + return OpenSyntax(node, name, inputs, StringSyntaxValue(p, provider), inputs), nil +} + func parseJoin(node *syntax.ObjectNode, name *StringExpr, args Expr) (Expr, syntax.Diagnostics) { list, ok := args.(*ListExpr) if !ok || len(list.Elements) != 2 {