Skip to content

Commit 045bed2

Browse files
stop blocking waiting for stack id
1 parent d7a9b87 commit 045bed2

File tree

5 files changed

+48
-32
lines changed

5 files changed

+48
-32
lines changed

cloud/aws/deploy/deploy.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,17 @@ func (a *NitricAwsPulumiProvider) Pre(ctx *pulumi.Context, resources []*pulumix.
146146
return err
147147
}
148148

149-
stackIdChan := make(chan string)
150-
pulumi.Sprintf("%s-%s", ctx.Stack(), stackRandId.Result).ApplyT(func(id string) string {
151-
stackIdChan <- id
152-
return id
153-
})
149+
a.StackId = "stack-id"
150+
151+
if !ctx.DryRun() {
152+
stackIdChan := make(chan string)
153+
pulumi.Sprintf("%s-%s", ctx.Stack(), stackRandId.Result).ApplyT(func(id string) string {
154+
stackIdChan <- id
155+
return id
156+
})
154157

155-
a.StackId = <-stackIdChan
158+
a.StackId = <-stackIdChan
159+
}
156160

157161
sess := session.Must(session.NewSessionWithOptions(session.Options{
158162
Config: aws.Config{Region: aws.String(a.Region)},

cloud/azure/deploy/deploy.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,17 @@ func (a *NitricAzurePulumiProvider) Pre(ctx *pulumi.Context, nitricResources []*
326326
return err
327327
}
328328

329-
stackIdChan := make(chan string)
330-
pulumi.Sprintf("%s-%s", ctx.Stack(), stackRandId.Result).ApplyT(func(id string) string {
331-
stackIdChan <- id
332-
return id
333-
})
329+
a.StackId = "stack-id"
330+
331+
if !ctx.DryRun() {
332+
stackIdChan := make(chan string)
333+
pulumi.Sprintf("%s-%s", ctx.Stack(), stackRandId.Result).ApplyT(func(id string) string {
334+
stackIdChan <- id
335+
return id
336+
})
334337

335-
a.StackId = <-stackIdChan
338+
a.StackId = <-stackIdChan
339+
}
336340

337341
a.ClientConfig, err = authorization.GetClientConfig(ctx)
338342
if err != nil {

cloud/common/deploy/provider/pulumi.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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{

cloud/common/deploy/provider/terraform.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (s *TerraformProviderServer) Down(req *deploymentspb.DeploymentDownRequest,
108108
return status.Error(codes.Unimplemented, "Down not implemented for Terraform providers, please run terraform destroy against your stack state")
109109
}
110110

111-
func (s *TerraformProviderServer) Preview(req *deploymentspb.DeploymentUpRequest, stream deploymentspb.Deployment_PreviewServer) error {
111+
func (s *TerraformProviderServer) Preview(req *deploymentspb.DeploymentPreviewRequest, stream deploymentspb.Deployment_PreviewServer) error {
112112
if beta, err := env.BETA_PROVIDERS.Bool(); err != nil || !beta {
113113
return status.Error(codes.FailedPrecondition, "Nitric terraform providers are currently in beta, please add beta-providers to the preview field of your nitric.yaml to enable")
114114
}

cloud/gcp/deploy/deploy.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,17 @@ func (a *NitricGcpPulumiProvider) Pre(ctx *pulumi.Context, resources []*pulumix.
190190
return err
191191
}
192192

193-
stackIdChan := make(chan string)
194-
pulumi.Sprintf("%s-%s", ctx.Stack(), stackRandId.Result).ApplyT(func(id string) string {
195-
stackIdChan <- id
196-
return id
197-
})
193+
a.StackId = "stack-id"
194+
195+
if !ctx.DryRun() {
196+
stackIdChan := make(chan string)
197+
pulumi.Sprintf("%s-%s", ctx.Stack(), stackRandId.Result).ApplyT(func(id string) string {
198+
stackIdChan <- id
199+
return id
200+
})
198201

199-
a.StackId = <-stackIdChan
202+
a.StackId = <-stackIdChan
203+
}
200204

201205
project, err := organizations.LookupProject(ctx, &organizations.LookupProjectArgs{
202206
ProjectId: &a.GcpConfig.ProjectId,

0 commit comments

Comments
 (0)