@@ -30,10 +30,11 @@ import (
3030 "github.com/hashicorp/hcl/v2"
3131 "github.com/hashicorp/hcl/v2/ext/customdecode"
3232 "github.com/pulumi/pulumi/pkg/v3/codegen/schema"
33- "github.com/pulumi/pulumi/pkg/v3/resource/plugin"
3433 "github.com/pulumi/pulumi/sdk/v3/go/common/resource"
3534 "github.com/pulumi/pulumi/sdk/v3/go/common/resource/archive"
3635 "github.com/pulumi/pulumi/sdk/v3/go/common/resource/asset"
36+ "github.com/pulumi/pulumi/sdk/v3/go/property"
37+ "github.com/pulumi/pulumi/sdk/v3/go/propertyrpc"
3738 pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go"
3839 "github.com/zclconf/go-cty/cty"
3940 "github.com/zclconf/go-cty/cty/function"
@@ -53,7 +54,7 @@ var invokeOptionsType = cty.ObjectWithOptionalAttrs(map[string]cty.Type{
5354
5455func tryExpressions (
5556 args []cty.Value ,
56- getResource func (context.Context , resource .ResourceReference ) (resource. PropertyMap , error ),
57+ getResource func (context.Context , property .ResourceReference ) (property. Map , error ),
5758) (cty.Value , error ) {
5859 if len (args ) == 0 {
5960 return cty .NilVal , errors .New ("at least one argument is required" )
@@ -100,7 +101,7 @@ func tryExpressions(
100101
101102func recoverExpression (
102103 args []cty.Value ,
103- getResource func (context.Context , resource .ResourceReference ) (resource. PropertyMap , error ),
104+ getResource func (context.Context , property .ResourceReference ) (property. Map , error ),
104105) (cty.Value , error ) {
105106 if len (args ) != 2 {
106107 return cty .NilVal , errors .New ("recover requires a value and recovery expression" )
@@ -266,8 +267,8 @@ func (ectx *EvalContext) builtinFunctions() map[string]function.Function {
266267 if err != nil {
267268 return cty .False , nil
268269 }
269- if pv .IsSecret () {
270- return propertyValueToCty (context .TODO (), ectx .getResource , resource . MakeSecret ( resource . NewProperty (true ) ))
270+ if pv .Secret () {
271+ return propertyValueToCty (context .TODO (), ectx .getResource , property . New ( true ). WithSecret (true ))
271272 }
272273 return cty .True , nil
273274 },
@@ -295,7 +296,6 @@ func (ectx *EvalContext) builtinFunctions() map[string]function.Function {
295296 if err != nil {
296297 return cty .DynamicVal , nil
297298 }
298- stackRefPV , _ = unwrapOutputs (stackRefPV )
299299 if stackRefPV .IsNull () {
300300 return cty .DynamicVal , nil
301301 }
@@ -354,29 +354,18 @@ func (ectx *EvalContext) builtinFunctions() map[string]function.Function {
354354 if err != nil {
355355 return cty .NilVal , fmt .Errorf ("invalid invoke arguments: %w" , err )
356356 }
357- argsPV , dependsOn := unwrapOutputs (argsPV )
357+ dependsOn := allDependencies (argsPV )
358358 if fun .Inputs != nil {
359- args , err := applySchemaInputs (argsPV .ObjectValue (), fun .Inputs .Properties )
359+ args , err := applySchemaInputs (argsPV .AsMap (), fun .Inputs .Properties )
360360 if err != nil {
361361 return cty .NilVal , fmt .Errorf ("convert invoke arguments: %w" , err )
362362 }
363- argsPV = resource .NewProperty (args )
364- }
365-
366- marshalOpts := plugin.MarshalOptions {
367- KeepUnknowns : true ,
368- KeepSecrets : true ,
369- KeepResources : true ,
370- KeepByteString : true ,
371- }
372- obj , err := plugin .MarshalProperties (argsPV .ObjectValue (), marshalOpts )
373- if err != nil {
374- return cty .NilVal , fmt .Errorf ("marshal invoke arguments: %w" , err )
363+ argsPV = property .New (args )
375364 }
376365
377366 request := & pulumirpc.ResourceInvokeRequest {
378367 Tok : token ,
379- Args : obj ,
368+ Args : propertyrpc . Marshal ( argsPV . AsMap ()) ,
380369 AcceptsByteString : true ,
381370 }
382371
@@ -442,35 +431,27 @@ func (ectx *EvalContext) builtinFunctions() map[string]function.Function {
442431 }
443432
444433 if resp .Unknown {
445- return propertyValueToCty (context .TODO (), ectx .getResource , resource .NewProperty (resource.Output {
446- Known : false ,
447- Dependencies : dependsOn ,
448- }))
434+ return propertyValueToCty (context .TODO (), ectx .getResource ,
435+ property .New (property .Computed ).WithDependencies (dependsOn ))
449436 }
450437
451- resultPM , err := plugin . UnmarshalProperties (resp .GetReturn (), marshalOpts )
438+ resultPM , err := propertyrpc . Unmarshal (resp .GetReturn ())
452439 if err != nil {
453440 return cty .NilVal , fmt .Errorf ("unmarshal invoke result: %w" , err )
454441 }
455442 // If this is a scalar invoke pull off the one property in the map
456- var resultPV resource. PropertyValue
443+ var resultPV property. Value
457444 if _ , ok := fun .ReturnType .(* schema.ObjectType ); ok {
458- resultPV = resource . NewProperty (resultPM )
445+ resultPV = property . New (resultPM )
459446 } else {
460- if len ( resultPM ) != 1 {
461- return cty .NilVal , fmt .Errorf ("expected scalar invoke result to have exactly one property, got %d" , len ( resultPM ))
447+ if resultPM . Len ( ) != 1 {
448+ return cty .NilVal , fmt .Errorf ("expected scalar invoke result to have exactly one property, got %d" , resultPM . Len ( ))
462449 }
463- for _ , v := range resultPM {
450+ for _ , v := range resultPM . All {
464451 resultPV = v
465452 }
466453 }
467- if len (dependsOn ) > 0 {
468- resultPV = resource .NewProperty (resource.Output {
469- Element : resultPV ,
470- Known : true ,
471- Dependencies : dependsOn ,
472- })
473- }
454+ resultPV = resultPV .WithDependencies (append (resultPV .Dependencies (), dependsOn ... ))
474455 return propertyValueToCty (context .TODO (), ectx .getResource , resultPV )
475456 },
476457 })
@@ -539,8 +520,8 @@ func (ectx *EvalContext) builtinFunctions() map[string]function.Function {
539520 if err != nil {
540521 return cty .NilVal , fmt .Errorf ("invalid invoke arguments: %w" , err )
541522 }
542- argsPV , _ = unwrapOutputs ( argsPV )
543- argsPM := argsPV . ObjectValue ()
523+ // A resource that is passed directly must not be a dependency of its own argument.
524+ argsPM := collapseResourceReferences ( argsPV ). AsMap ()
544525 if fun .Inputs != nil {
545526 argsPM , err = applySchemaInputs (argsPM , fun .Inputs .Properties )
546527 if err != nil {
@@ -558,30 +539,18 @@ func (ectx *EvalContext) builtinFunctions() map[string]function.Function {
558539 }
559540
560541 // The ID is unknown when self is a resource still being created during a preview.
561- idPV := resource . MakeComputed ( resource . NewProperty ( "" ) )
542+ idPV := property . New ( property . Computed )
562543 if id .IsKnown () {
563- idPV = resource . NewProperty (id .AsString ())
544+ idPV = property . New (id .AsString ())
564545 }
565- argsPM [ "__self__" ] = resource . NewProperty (resource .ResourceReference {
546+ argsPM = argsPM . Set ( "__self__" , property . New (property .ResourceReference {
566547 URN : resource .URN (urnVal .AsString ()),
567548 ID : idPV ,
568- })
569-
570- marshalOpts := plugin.MarshalOptions {
571- KeepUnknowns : true ,
572- KeepSecrets : true ,
573- KeepResources : true ,
574- KeepOutputValues : true ,
575- KeepByteString : true ,
576- }
577- obj , err := plugin .MarshalProperties (argsPM , marshalOpts )
578- if err != nil {
579- return cty .NilVal , fmt .Errorf ("marshal invoke arguments: %w" , err )
580- }
549+ }))
581550
582551 request := & pulumirpc.ResourceCallRequest {
583552 Tok : fun .Token ,
584- Args : obj ,
553+ Args : propertyrpc . Marshal ( argsPM ) ,
585554 AcceptsByteString : true ,
586555 }
587556
@@ -626,36 +595,30 @@ func (ectx *EvalContext) builtinFunctions() map[string]function.Function {
626595 return cty .NilVal , errors .New (buf .String ())
627596 }
628597
629- resultPM , err := plugin . UnmarshalProperties (resp .GetReturn (), marshalOpts )
598+ resultPM , err := propertyrpc . Unmarshal (resp .GetReturn ())
630599 if err != nil {
631600 return cty .NilVal , fmt .Errorf ("unmarshal invoke result: %w" , err )
632601 }
633602 // Methods declared with ReturnTypePlain but no object return type carry the single value in a
634603 // property map with exactly one entry, whose key may be any name. Unwrap it so callers get the
635604 // value directly.
636- var resultPV resource. PropertyValue
605+ var resultPV property. Value
637606 if fun .ReturnTypePlain {
638607 if _ , isObject := fun .ReturnType .(* schema.ObjectType ); ! isObject {
639- if len ( resultPM ) != 1 {
608+ if resultPM . Len ( ) != 1 {
640609 return cty .NilVal , fmt .Errorf (
641- "invoke %q: expected a single return value, got %d" , fun .Token , len ( resultPM ))
610+ "invoke %q: expected a single return value, got %d" , fun .Token , resultPM . Len ( ))
642611 }
643- for _ , v := range resultPM {
612+ for _ , v := range resultPM . All {
644613 resultPV = v
645614 }
646615 } else {
647- resultPV = resource . NewProperty (resultPM )
616+ resultPV = property . New (resultPM )
648617 }
649618 } else {
650- resultPV = resource .NewProperty (resultPM )
651- }
652- if len (dependsOn ) > 0 {
653- resultPV = resource .NewProperty (resource.Output {
654- Element : resultPV ,
655- Known : true ,
656- Dependencies : dependsOn ,
657- })
619+ resultPV = property .New (resultPM )
658620 }
621+ resultPV = resultPV .WithDependencies (append (resultPV .Dependencies (), dependsOn ... ))
659622 return propertyValueToCty (context .TODO (), ectx .getResource , resultPV )
660623 },
661624 })
@@ -680,7 +643,7 @@ func (ectx *EvalContext) builtinFunctions() map[string]function.Function {
680643 if err != nil {
681644 return cty .NilVal , fmt .Errorf ("creating file asset: %w" , err )
682645 }
683- return propertyValueToCty (context .TODO (), ectx .getResource , resource . NewProperty (a ))
646+ return propertyValueToCty (context .TODO (), ectx .getResource , property . New (a ))
684647 },
685648 })
686649
@@ -704,7 +667,7 @@ func (ectx *EvalContext) builtinFunctions() map[string]function.Function {
704667 if err != nil {
705668 return cty .NilVal , fmt .Errorf ("creating file archive: %w" , err )
706669 }
707- return propertyValueToCty (context .TODO (), ectx .getResource , resource . NewProperty (a ))
670+ return propertyValueToCty (context .TODO (), ectx .getResource , property . New (a ))
708671 },
709672 })
710673
@@ -733,7 +696,7 @@ func (ectx *EvalContext) builtinFunctions() map[string]function.Function {
733696 if err != nil {
734697 return cty .NilVal , fmt .Errorf ("creating archive from assets: %w" , err )
735698 }
736- return propertyValueToCty (context .TODO (), ectx .getResource , resource . NewProperty (a ))
699+ return propertyValueToCty (context .TODO (), ectx .getResource , property . New (a ))
737700 },
738701 })
739702
@@ -757,7 +720,7 @@ func (ectx *EvalContext) builtinFunctions() map[string]function.Function {
757720 if err != nil {
758721 return cty .NilVal , fmt .Errorf ("creating string asset: %w" , err )
759722 }
760- return propertyValueToCty (context .TODO (), ectx .getResource , resource . NewProperty (a ))
723+ return propertyValueToCty (context .TODO (), ectx .getResource , property . New (a ))
761724 },
762725 })
763726
@@ -781,7 +744,7 @@ func (ectx *EvalContext) builtinFunctions() map[string]function.Function {
781744 if err != nil {
782745 return cty .NilVal , fmt .Errorf ("creating remote asset: %w" , err )
783746 }
784- return propertyValueToCty (context .TODO (), ectx .getResource , resource . NewProperty (a ))
747+ return propertyValueToCty (context .TODO (), ectx .getResource , property . New (a ))
785748 },
786749 })
787750
@@ -805,7 +768,7 @@ func (ectx *EvalContext) builtinFunctions() map[string]function.Function {
805768 if err != nil {
806769 return cty .NilVal , fmt .Errorf ("creating remote archive: %w" , err )
807770 }
808- return propertyValueToCty (context .TODO (), ectx .getResource , resource . NewProperty (a ))
771+ return propertyValueToCty (context .TODO (), ectx .getResource , property . New (a ))
809772 },
810773 })
811774
0 commit comments