Skip to content

Commit

Permalink
Enable l1-stack-refernce test (#686)
Browse files Browse the repository at this point in the history
This required two fixes. One to handle `getOutput` functions in PCL and
rewrite them into variable expressions. e.g. `getOutput(res, "key")`
gets rewritten to `${res.outputs["key"]}`.

Secondly resources in the "pulumi" package, like stack reference
resources, don't need a "pulumi" plugin so don't return that in
GetRequiredPlugins.
  • Loading branch information
Frassle authored Nov 15, 2024
1 parent 7a20d68 commit 429991d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/unreleased/Improvements-686.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
component: codegen
kind: Improvements
body: Support stack references in program generation
time: 2024-11-15T17:19:10.259289815Z
custom:
PR: "686"
1 change: 0 additions & 1 deletion cmd/pulumi-language-yaml/language_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ func runTestingHost(t *testing.T) (string, testingrpc.LanguageTestClient) {

// Add test names here that are expected to fail and the reason why they are failing
var expectedFailures = map[string]string{
"l1-stack-reference": "YAML does not support fn::getOutput",
"l2-invoke-options": "cannot assign expression",
"l2-provider-grpc-config-schema-secret": "Detected a secret leak in state",
"l2-parameterized-resource": "could not load schema for subpackage, provider not known",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resources:
ref:
type: pulumi:pulumi:StackReference
properties:
name: organization/other/dev
outputs:
plain: ${ref.outputs["plain"]}
secret: ${ref.outputs["secret"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: l1-stack-reference
runtime: yaml
14 changes: 14 additions & 0 deletions pkg/pulumiyaml/codegen/gen_program.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,20 @@ func (g *generator) function(f *model.FunctionCallExpression) syn.Node {
return wrapFn("readFile", g.expr(f.Args[0]))
case "secret":
return wrapFn("secret", g.expr(f.Args[0]))
case "getOutput":
// getOutput(var, key) => ${var.outputs[key]}

root := g.expr(f.Args[0]).String() // This will be something like ${var}
// Strip the ${} from the root as we're going to rewrap it
root = root[2 : len(root)-1]

key := g.expr(f.Args[1])
// We need to wrap the key in quotes if its a string, but not if its a number
if _, ok := key.(*syn.StringNode); ok {
key = syn.String(fmt.Sprintf("%q", key.String()))
}

return syn.String(fmt.Sprintf("${%s.outputs[%s]}", root, key))
case pcl.IntrinsicConvert:
// We can't perform the convert, but it might happen automatically.
// This works for enums, as well as number -> strings.
Expand Down
5 changes: 5 additions & 0 deletions pkg/pulumiyaml/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ func GetReferencedPlugins(tmpl *ast.TemplateDecl) ([]Plugin, syntax.Diagnostics)

acceptType := func(r *Runner, typeName string, version, pluginDownloadURL *ast.StringExpr) {
pkg := ResolvePkgName(typeName)
// skip the "pulumi" package
if pkg == "pulumi" {
return
}

if entry, found := pluginMap[pkg]; found {
if v := version.GetValue(); v != "" && entry.version != v {
if entry.version == "" {
Expand Down

0 comments on commit 429991d

Please sign in to comment.