Skip to content

Commit

Permalink
Merge #11353
Browse files Browse the repository at this point in the history
11353: Add experimental use plan option to up r=justinvp a=Frassle

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->
Adds an option to use plans in the update prompt:
```
Do you want to perform this update?  [Use arrows to move, type to filter]
> [experimental] yes, using Update Plans (https://pulumi.com/updateplans)
  yes
  no
  details
```

Needs at least pulumi/pulumi-hugo#2230 merged and published first.

Fixes #9687

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Fraser Waters <fraser@pulumi.com>
  • Loading branch information
bors[bot] and Frassle committed Nov 22, 2022
2 parents 45dddd8 + e6268f0 commit 1c3beb1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
@@ -0,0 +1,4 @@
changes:
- type: feat
scope: cli
description: Add prompt to `up` to use experimental update plans.
30 changes: 22 additions & 8 deletions pkg/backend/apply.go
Expand Up @@ -75,6 +75,7 @@ type response string

const (
yes response = "yes"
yesPlan response = "[experimental] yes, using Update Plans (https://pulumi.com/updateplans)"
no response = "no"
details response = "details"
)
Expand Down Expand Up @@ -133,14 +134,14 @@ func PreviewThenPrompt(ctx context.Context, kind apitype.UpdateKind, stack Stack
}

// Otherwise, ensure the user wants to proceed.
res = confirmBeforeUpdating(kind, stack, events, op.Opts)
res, plan = confirmBeforeUpdating(kind, stack, events, plan, op.Opts)
close(eventsChannel)
return plan, changes, res
}

// confirmBeforeUpdating asks the user whether to proceed. A nil error means yes.
func confirmBeforeUpdating(kind apitype.UpdateKind, stack Stack,
events []engine.Event, opts UpdateOptions) result.Result {
events []engine.Event, plan *deploy.Plan, opts UpdateOptions) (result.Result, *deploy.Plan) {
for {
var response string

Expand All @@ -152,6 +153,12 @@ func confirmBeforeUpdating(kind apitype.UpdateKind, stack Stack,

choices := []string{string(yes), string(no)}

// If we have a new plan but didn't start with a plan we can prompt to use the new plan.
// If we're in experimental mode we don't add this because "yes" will also use the plan
if plan != nil && opts.Engine.Plan == nil && !opts.Engine.Experimental {
choices = append([]string{string(yesPlan)}, choices...)
}

// For non-previews, we can also offer a detailed summary.
if !opts.SkipPreview {
choices = append(choices, string(details))
Expand Down Expand Up @@ -179,16 +186,23 @@ func confirmBeforeUpdating(kind apitype.UpdateKind, stack Stack,
Options: choices,
Default: string(no),
}, &response, surveyIcons); err != nil {
return result.FromError(fmt.Errorf("confirmation cancelled, not proceeding with the %s: %w", kind, err))
return result.FromError(fmt.Errorf("confirmation cancelled, not proceeding with the %s: %w", kind, err)), nil
}

if response == string(no) {
fmt.Printf("confirmation declined, not proceeding with the %s\n", kind)
return result.Bail()
return result.Bail(), nil
}

if response == string(yes) {
return nil
// If we're in experimental mode always use the plan
if opts.Engine.Experimental {
return nil, plan
}
return nil, nil
}
if response == string(yesPlan) {
return nil, plan
}

if response == string(details) {
Expand Down Expand Up @@ -219,11 +233,11 @@ func PreviewThenPromptThenExecute(ctx context.Context, kind apitype.UpdateKind,
return changes, res
}

// If we had an original plan use it, else if experimental use the newly generated plan (might be nil if we've turned
// plan generation off)
// If we had an original plan use it, else if prompt said to use the plan from Preview then use the
// newly generated plan
if originalPlan != nil {
op.Opts.Engine.Plan = originalPlan
} else if op.Opts.Engine.Experimental {
} else if plan != nil {
op.Opts.Engine.Plan = plan
} else {
op.Opts.Engine.Plan = nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/backend/httpstate/backend.go
Expand Up @@ -1166,7 +1166,7 @@ func (b *cloudBackend) runEngineAction(
case apitype.PreviewUpdate:
plan, changes, res = engine.Update(u, engineCtx, op.Opts.Engine, true)
case apitype.UpdateUpdate:
_, changes, res = engine.Update(u, engineCtx, op.Opts.Engine, dryRun)
plan, changes, res = engine.Update(u, engineCtx, op.Opts.Engine, dryRun)
case apitype.ResourceImportUpdate:
_, changes, res = engine.Import(u, engineCtx, op.Opts.Engine, op.Imports, dryRun)
case apitype.RefreshUpdate:
Expand Down

0 comments on commit 1c3beb1

Please sign in to comment.