@@ -28,7 +28,9 @@ import (
2828 "github.com/pulumi/pulumi/sdk/v3/go/auto"
2929 "github.com/pulumi/pulumi/sdk/v3/go/auto/events"
3030 "github.com/pulumi/pulumi/sdk/v3/go/auto/optdestroy"
31+ "github.com/pulumi/pulumi/sdk/v3/go/auto/optpreview"
3132 "github.com/pulumi/pulumi/sdk/v3/go/auto/optup"
33+ "github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
3234 "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
3335 "google.golang.org/grpc"
3436 "google.golang.org/grpc/codes"
@@ -73,7 +75,7 @@ func nitricResourceToPulumiResource(res *deploymentspb.Resource) *pulumix.Nitric
7375 }
7476}
7577
76- func createPulumiProgramForNitricProvider (req * deploymentspb.DeploymentUpRequest , nitricProvider NitricPulumiProvider , runtime RuntimeProvider ) func (* pulumi.Context ) error {
78+ func createPulumiProgramForNitricProvider (spec * deploymentspb.Spec , nitricProvider NitricPulumiProvider , runtime RuntimeProvider ) func (* pulumi.Context ) error {
7779 return func (ctx * pulumi.Context ) (err error ) {
7880 defer func () {
7981 if r := recover (); r != nil {
@@ -83,8 +85,8 @@ func createPulumiProgramForNitricProvider(req *deploymentspb.DeploymentUpRequest
8385 }()
8486
8587 // Need to convert the Nitric resources to Pulumi resources, this will allow us to extend their configurations with pulumi inputs/outputs
86- pulumiResources := make ([]* pulumix.NitricPulumiResource [any ], 0 , len (req . Spec .Resources ))
87- for _ , res := range nitricProvider .Order (req . Spec .Resources ) {
88+ pulumiResources := make ([]* pulumix.NitricPulumiResource [any ], 0 , len (spec .Resources ))
89+ for _ , res := range nitricProvider .Order (spec .Resources ) {
8890 pulumiResources = append (pulumiResources , nitricResourceToPulumiResource (res ))
8991 }
9092
@@ -224,7 +226,7 @@ func (s *PulumiProviderServer) Up(req *deploymentspb.DeploymentUpRequest, stream
224226 return err
225227 }
226228
227- pulumiProgram := createPulumiProgramForNitricProvider (req , s .provider , s .runtime )
229+ pulumiProgram := createPulumiProgramForNitricProvider (req . Spec , s .provider , s .runtime )
228230
229231 autoStack , err := auto .UpsertStackInlineSource (context .TODO (), fmt .Sprintf ("%s-%s" , projectName , stackName ), projectName , pulumiProgram )
230232 if err != nil {
@@ -344,7 +346,7 @@ func (s *PulumiProviderServer) Down(req *deploymentspb.DeploymentDownRequest, st
344346}
345347
346348// Preview - automatically called by the Nitric CLI via the `preview` command
347- func (s * PulumiProviderServer ) Preview (req * deploymentspb.DeploymentUpRequest , stream deploymentspb.Deployment_PreviewServer ) error {
349+ func (s * PulumiProviderServer ) Preview (req * deploymentspb.DeploymentPreviewRequest , stream deploymentspb.Deployment_PreviewServer ) error {
348350 // Verify if dependencies are available
349351 if err := checkDependencies (checkPulumiAvailable , checkDockerAvailable ); err != nil {
350352 return status .Error (codes .FailedPrecondition , err .Error ())
@@ -362,7 +364,7 @@ func (s *PulumiProviderServer) Preview(req *deploymentspb.DeploymentUpRequest, s
362364 return err
363365 }
364366
365- pulumiProgram := createPulumiProgramForNitricProvider (req , s .provider , s .runtime )
367+ pulumiProgram := createPulumiProgramForNitricProvider (req . Spec , s .provider , s .runtime )
366368
367369 autoStack , err := auto .UpsertStackInlineSource (context .TODO (), fmt .Sprintf ("%s-%s" , projectName , stackName ), projectName , pulumiProgram )
368370 if err != nil {
@@ -388,13 +390,13 @@ func (s *PulumiProviderServer) Preview(req *deploymentspb.DeploymentUpRequest, s
388390
389391 refresh , ok := attributesMap ["refresh" ].(bool )
390392
391- options := []optup .Option {optup .EventStreams (pulumiEventsChan )}
393+ options := []optpreview .Option {optpreview .EventStreams (pulumiEventsChan )}
392394
393395 if ok && refresh {
394- options = append (options , optup .Refresh ())
396+ options = append (options , optpreview .Refresh ())
395397 }
396398
397- result , err := autoStack .Up (context .TODO (), options ... )
399+ result , err := autoStack .Preview (context .TODO (), options ... )
398400 if err != nil {
399401 err = handleCommonErrors (err )
400402
@@ -405,10 +407,12 @@ func (s *PulumiProviderServer) Preview(req *deploymentspb.DeploymentUpRequest, s
405407 return err
406408 }
407409
408- resultStr , ok := result .Outputs [resultCtxKey ].Value .(string )
409- if ! ok {
410- resultStr = ""
411- }
410+ // Plan 2 to add, 0 to change, 3 to destroy.
411+ resultStr := fmt .Sprintf ("Plan: %d to add, %d to change, %d to destroy." ,
412+ result .ChangeSummary [apitype .OpCreate ],
413+ result .ChangeSummary [apitype .OpUpdate ],
414+ result .ChangeSummary [apitype .OpDelete ],
415+ )
412416
413417 err = stream .Send (& deploymentspb.DeploymentPreviewEvent {
414418 Content : & deploymentspb.DeploymentPreviewEvent_Result {
0 commit comments