diff --git a/pkg/backend/filestate/stack.go b/pkg/backend/filestate/stack.go index a886507b4..2d9d9325a 100644 --- a/pkg/backend/filestate/stack.go +++ b/pkg/backend/filestate/stack.go @@ -64,7 +64,10 @@ func (s *localStack) Rename(ctx context.Context, newName tokens.QName) (backend. return backend.RenameStack(ctx, s, newName) } -func (s *localStack) Preview(ctx context.Context, op backend.UpdateOperation) (deploy.Plan, engine.ResourceChanges, result.Result) { +func (s *localStack) Preview( + ctx context.Context, + op backend.UpdateOperation) (deploy.Plan, engine.ResourceChanges, result.Result) { + return backend.PreviewStack(ctx, s, op) } diff --git a/pkg/backend/httpstate/stack.go b/pkg/backend/httpstate/stack.go index 8b34ac741..a94020d6f 100644 --- a/pkg/backend/httpstate/stack.go +++ b/pkg/backend/httpstate/stack.go @@ -140,7 +140,10 @@ func (s *cloudStack) Rename(ctx context.Context, newName tokens.QName) (backend. return backend.RenameStack(ctx, s, newName) } -func (s *cloudStack) Preview(ctx context.Context, op backend.UpdateOperation) (deploy.Plan, engine.ResourceChanges, result.Result) { +func (s *cloudStack) Preview( + ctx context.Context, + op backend.UpdateOperation) (deploy.Plan, engine.ResourceChanges, result.Result) { + return backend.PreviewStack(ctx, s, op) } diff --git a/pkg/backend/mock.go b/pkg/backend/mock.go index f194fd40a..0158f3006 100644 --- a/pkg/backend/mock.go +++ b/pkg/backend/mock.go @@ -381,7 +381,10 @@ func (ms *MockStack) Backend() Backend { panic("not implemented") } -func (ms *MockStack) Preview(ctx context.Context, op UpdateOperation) (deploy.Plan, engine.ResourceChanges, result.Result) { +func (ms *MockStack) Preview( + ctx context.Context, + op UpdateOperation) (deploy.Plan, engine.ResourceChanges, result.Result) { + if ms.PreviewF != nil { return ms.PreviewF(ctx, op) } diff --git a/pkg/backend/stack.go b/pkg/backend/stack.go index f0910518b..05c82ec38 100644 --- a/pkg/backend/stack.go +++ b/pkg/backend/stack.go @@ -75,7 +75,11 @@ func RenameStack(ctx context.Context, s Stack, newName tokens.QName) (StackRefer } // PreviewStack previews changes to this stack. -func PreviewStack(ctx context.Context, s Stack, op UpdateOperation) (deploy.Plan, engine.ResourceChanges, result.Result) { +func PreviewStack( + ctx context.Context, + s Stack, + op UpdateOperation) (deploy.Plan, engine.ResourceChanges, result.Result) { + return s.Backend().Preview(ctx, s, op) } @@ -119,7 +123,10 @@ func GetStackLogs(ctx context.Context, s Stack, cfg StackConfiguration, } // ExportStackDeployment exports the given stack's deployment as an opaque JSON message. -func ExportStackDeployment(ctx context.Context, s Stack) (*apitype.UntypedDeployment, error) { +func ExportStackDeployment( + ctx context.Context, + s Stack) (*apitype.UntypedDeployment, error) { + return s.Backend().ExportDeployment(ctx, s) } diff --git a/pkg/cmd/pulumi/plan.go b/pkg/cmd/pulumi/plan.go index d406cc197..e6cf3f3bf 100644 --- a/pkg/cmd/pulumi/plan.go +++ b/pkg/cmd/pulumi/plan.go @@ -21,6 +21,7 @@ import ( "github.com/pulumi/pulumi/pkg/v3/backend/display" "github.com/pulumi/pulumi/pkg/v3/resource/deploy" + "github.com/pulumi/pulumi/pkg/v3/util" "github.com/pulumi/pulumi/sdk/v3/go/common/diag/colors" "github.com/pulumi/pulumi/sdk/v3/go/common/resource" "github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil" @@ -104,25 +105,25 @@ type planNode struct { func renderPlanNode(node *planNode, padding, branch string, rows *[]cmdutil.TableRow, color colors.Colorization) { padBranch := "" switch branch { - case "├─ ": - padBranch = "│ " - case "└─ ": - padBranch = " " + case util.TBranchString: + padBranch = util.TPaddingString + case util.LBranchString: + padBranch = util.LPaddingString } childPadding := padding + padBranch - infoBranch := " " + infoBranch := util.LPaddingString if len(node.children) > 0 { - infoBranch = "│ " + infoBranch = util.TPaddingString } infoPadding := childPadding + infoBranch *rows = append(*rows, renderResourcePlan(node.urn, node.plan, padding+branch, infoPadding, color)) for i, child := range node.children { - childBranch := "├─ " + childBranch := util.TBranchString if i == len(node.children)-1 { - childBranch = "└─ " + childBranch = util.LBranchString } renderPlanNode(child, childPadding, childBranch, rows, color) } @@ -198,7 +199,13 @@ func renderPlan(plan deploy.Plan, showSames bool, color colors.Colorization) []c return rows } -func renderResourcePlan(urn resource.URN, plan *deploy.ResourcePlan, prefix, infoPrefix string, color colors.Colorization) cmdutil.TableRow { +func renderResourcePlan( + urn resource.URN, + plan *deploy.ResourcePlan, + prefix, + infoPrefix string, + color colors.Colorization) cmdutil.TableRow { + displayOp := deploy.OpSame if plan != nil { for _, op := range plan.Ops { diff --git a/pkg/cmd/pulumi/stack.go b/pkg/cmd/pulumi/stack.go index 5a899e766..e23046ea3 100644 --- a/pkg/cmd/pulumi/stack.go +++ b/pkg/cmd/pulumi/stack.go @@ -26,6 +26,7 @@ import ( "github.com/pulumi/pulumi/pkg/v3/backend/display" "github.com/pulumi/pulumi/pkg/v3/backend/httpstate" "github.com/pulumi/pulumi/pkg/v3/resource/deploy" + "github.com/pulumi/pulumi/pkg/v3/util" "github.com/pulumi/pulumi/sdk/v3/go/common/resource" "github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil" ) @@ -234,25 +235,25 @@ type treeNode struct { func renderNode(node *treeNode, padding, branch string, showURNs, showIDs bool, rows *[]cmdutil.TableRow) { padBranch := "" switch branch { - case "├─ ": - padBranch = "│ " - case "└─ ": - padBranch = " " + case util.TBranchString: + padBranch = util.TPaddingString + case util.LBranchString: + padBranch = util.LPaddingString } childPadding := padding + padBranch - infoBranch := " " + infoBranch := util.LPaddingString if len(node.children) > 0 { - infoBranch = "│ " + infoBranch = util.TPaddingString } infoPadding := childPadding + infoBranch *rows = append(*rows, renderResourceRow(node.res, padding+branch, infoPadding, showURNs, showIDs)) for i, child := range node.children { - childBranch := "├─ " + childBranch := util.TBranchString if i == len(node.children)-1 { - childBranch = "└─ " + childBranch = util.LBranchString } renderNode(child, childPadding, childBranch, showURNs, showIDs, rows) } diff --git a/pkg/engine/destroy.go b/pkg/engine/destroy.go index 9aeca4f33..484cd233d 100644 --- a/pkg/engine/destroy.go +++ b/pkg/engine/destroy.go @@ -23,7 +23,12 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/workspace" ) -func Destroy(u UpdateInfo, ctx *Context, opts UpdateOptions, dryRun bool) (deploy.Plan, ResourceChanges, result.Result) { +func Destroy( + u UpdateInfo, + ctx *Context, + opts UpdateOptions, + dryRun bool) (deploy.Plan, ResourceChanges, result.Result) { + contract.Require(u != nil, "u") contract.Require(ctx != nil, "ctx") diff --git a/pkg/engine/refresh.go b/pkg/engine/refresh.go index 8becfcf72..e69ca93c2 100644 --- a/pkg/engine/refresh.go +++ b/pkg/engine/refresh.go @@ -23,7 +23,12 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/workspace" ) -func Refresh(u UpdateInfo, ctx *Context, opts UpdateOptions, dryRun bool) (deploy.Plan, ResourceChanges, result.Result) { +func Refresh( + u UpdateInfo, + ctx *Context, + opts UpdateOptions, + dryRun bool) (deploy.Plan, ResourceChanges, result.Result) { + contract.Require(u != nil, "u") contract.Require(ctx != nil, "ctx") diff --git a/pkg/resource/deploy/deployment.go b/pkg/resource/deploy/deployment.go index ff23ab6d3..f27488915 100644 --- a/pkg/resource/deploy/deployment.go +++ b/pkg/resource/deploy/deployment.go @@ -147,7 +147,13 @@ func (m *resourceMap) mapRange(callback func(urn resource.URN, state *resource.S type resourcePlans struct { m sync.RWMutex - plans map[resource.URN]*ResourcePlan + plans Plan +} + +func newResourcePlan() *resourcePlans { + return &resourcePlans{ + plans: make(Plan), + } } func (m *resourcePlans) set(urn resource.URN, plan *ResourcePlan) { @@ -378,7 +384,7 @@ func NewDeployment(ctx *plugin.Context, target *Target, prev *Snapshot, plan Pla providers: reg, goals: newGoals, news: newResources, - newPlans: &resourcePlans{}, + newPlans: newResourcePlan(), }, nil } diff --git a/pkg/resource/deploy/deployment_executor.go b/pkg/resource/deploy/deployment_executor.go index c83a3013d..6c6cb1b99 100644 --- a/pkg/resource/deploy/deployment_executor.go +++ b/pkg/resource/deploy/deployment_executor.go @@ -433,7 +433,11 @@ func (ex *deploymentExecutor) retirePendingDeletes(callerCtx context.Context, op } // import imports a list of resources into a stack. -func (ex *deploymentExecutor) importResources(callerCtx context.Context, opts Options, preview bool) (Plan, result.Result) { +func (ex *deploymentExecutor) importResources( + callerCtx context.Context, + opts Options, + preview bool) (Plan, result.Result) { + if len(ex.deployment.imports) == 0 { return nil, nil } diff --git a/pkg/resource/deploy/import.go b/pkg/resource/deploy/import.go index 6f22f712c..0e626946c 100644 --- a/pkg/resource/deploy/import.go +++ b/pkg/resource/deploy/import.go @@ -97,6 +97,7 @@ func NewImportDeployment(ctx *plugin.Context, target *Target, projectName tokens source: NewErrorSource(projectName), preview: preview, providers: reg, + newPlans: newResourcePlan(), }, nil } diff --git a/pkg/resource/deploy/plan.go b/pkg/resource/deploy/plan.go index 41f6bed58..85923bb2c 100644 --- a/pkg/resource/deploy/plan.go +++ b/pkg/resource/deploy/plan.go @@ -174,7 +174,8 @@ func (rp *ResourcePlan) checkGoal(programGoal *resource.Goal) error { } // Check that the additionalSecretOutputs sets are identical. - if message, changed := rp.diffPropertyKeys(rp.Goal.AdditionalSecretOutputs, programGoal.AdditionalSecretOutputs); changed { + if message, changed := rp.diffPropertyKeys( + rp.Goal.AdditionalSecretOutputs, programGoal.AdditionalSecretOutputs); changed { return fmt.Errorf("additionalSecretOutputs changed: %v", message) } diff --git a/pkg/resource/stack/plan.go b/pkg/resource/stack/plan.go index d529bb208..4627791a7 100644 --- a/pkg/resource/stack/plan.go +++ b/pkg/resource/stack/plan.go @@ -7,7 +7,11 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/common/resource/config" ) -func SerializeResourcePlan(plan *deploy.ResourcePlan, enc config.Encrypter, showSecrets bool) (apitype.ResourcePlanV1, error) { +func SerializeResourcePlan( + plan *deploy.ResourcePlan, + enc config.Encrypter, + showSecrets bool) (apitype.ResourcePlanV1, error) { + properties, err := SerializeProperties(plan.Goal.Properties, enc, showSecrets) if err != nil { return apitype.ResourcePlanV1{}, err @@ -64,7 +68,11 @@ func SerializePlan(plan deploy.Plan, enc config.Encrypter, showSecrets bool) (ap return apitype.DeploymentPlanV1{ResourcePlans: resourcePlans}, nil } -func DeserializeResourcePlan(plan apitype.ResourcePlanV1, dec config.Decrypter, enc config.Encrypter) (*deploy.ResourcePlan, error) { +func DeserializeResourcePlan( + plan apitype.ResourcePlanV1, + dec config.Decrypter, + enc config.Encrypter) (*deploy.ResourcePlan, error) { + properties, err := DeserializeProperties(plan.Goal.Properties, dec, enc) if err != nil { return nil, err diff --git a/pkg/util/display.go b/pkg/util/display.go new file mode 100644 index 000000000..17fb9958b --- /dev/null +++ b/pkg/util/display.go @@ -0,0 +1,6 @@ +package util + +const TBranchString = "├─ " +const LBranchString = "└─ " +const TPaddingString = "│ " +const LPaddingString = " " diff --git a/sdk/go/common/resource/properties_diff.go b/sdk/go/common/resource/properties_diff.go index 0978b7320..ee384c792 100644 --- a/sdk/go/common/resource/properties_diff.go +++ b/sdk/go/common/resource/properties_diff.go @@ -457,8 +457,8 @@ func (v PropertyValue) DeepEquals(other PropertyValue) bool { return v.V == other.V } -func (m PropertyMap) ConstrainedTo(constraints PropertyMap) (*ObjectDiff, bool) { - diff := constraints.diff(m, true, nil) +func (props PropertyMap) ConstrainedTo(constraints PropertyMap) (*ObjectDiff, bool) { + diff := constraints.diff(props, true, nil) return diff, diff == nil }