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

Enable l1-stack-refernce test #686

Merged
merged 1 commit into from
Nov 15, 2024
Merged
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
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
Loading