Skip to content

Commit

Permalink
add support for --import-file when using the Automation API (#16071)
Browse files Browse the repository at this point in the history
<!--- 
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. -->

Fixes # (issue)

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [x] I have formatted my code using `gofumpt`

<!--- 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 Cloud,
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
Cloud API version
<!-- @pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->

---------

Co-authored-by: Thomas Gummerer <[email protected]>
  • Loading branch information
charlie-haley and tgummerer committed Apr 30, 2024
1 parent a514601 commit b57c60f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- type: feat
scope: auto/go,nodejs,python
description: Add support for --import-file option on Preview with Automation API
2 changes: 1 addition & 1 deletion pkg/cmd/pulumi/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ func newPreviewCmd() *cobra.Command {
}
cmd.PersistentFlags().StringVar(
&importFilePath, "import-file", "",
"Save any creates seen during the preview into an import file to use with `pulumi import`")
"Save any creates seen during the preview into an import file to use with 'pulumi import'")

cmd.Flags().BoolVarP(
&showSecrets, "show-secrets", "", false, "Emit secrets in plaintext in the plan file. Defaults to `false`")
Expand Down
9 changes: 9 additions & 0 deletions sdk/go/auto/optpreview/optpreview.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ func SuppressOutputs() Option {
})
}

// ImportFile save any creates seen during the preview into an import file to use with pulumi import
func ImportFile(path string) Option {
return optionFunc(func(opts *Options) {
opts.ImportFile = path
})
}

// Option is a parameter to be applied to a Stack.Preview() operation
type Option interface {
ApplyOption(*Options)
Expand Down Expand Up @@ -184,6 +191,8 @@ type Options struct {
SuppressProgress bool
// Suppress display of stack outputs (in case they contain sensitive values)
SuppressOutputs bool
// Save any creates seen during the preview into an import file to use with pulumi import
ImportFile string
}

type optionFunc func(*Options)
Expand Down
3 changes: 3 additions & 0 deletions sdk/go/auto/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ func (s *Stack) Preview(ctx context.Context, opts ...optpreview.Option) (Preview
if preOpts.SuppressProgress {
sharedArgs = append(sharedArgs, "--suppress-progress")
}
if preOpts.ImportFile != "" {
sharedArgs = append(sharedArgs, "--import-file="+preOpts.ImportFile)
}

// Apply the remote args, if needed.
sharedArgs = append(sharedArgs, s.remoteArgs()...)
Expand Down
7 changes: 7 additions & 0 deletions sdk/nodejs/automation/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ Event: ${line}\n${e.toString()}`);
if (opts.plan) {
args.push("--save-plan", opts.plan);
}
if (opts.importFile) {
args.push("--import-file", opts.importFile);
}
applyGlobalOpts(opts, args);
}

Expand Down Expand Up @@ -914,6 +917,10 @@ export interface GlobalOpts {
* Suppress display of periodic progress dots
*/
suppressProgress?: boolean;
/**
* Save any creates seen during the preview into an import file to use with pulumi import
*/
importFile?: string;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions sdk/python/lib/pulumi/automation/_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ def preview(
debug: Optional[bool] = None,
suppress_outputs: Optional[bool] = None,
suppress_progress: Optional[bool] = None,
import_file: Optional[str] = None,
) -> PreviewResult:
"""
Performs a dry-run update to a stack, returning pending changes.
Expand Down Expand Up @@ -377,6 +378,7 @@ def preview(
:param debug: Print detailed debugging output during resource operations
:param suppress_outputs: Suppress display of stack outputs (in case they contain sensitive values)
:param suppress_progress: Suppress display of periodic progress dots
:param import_file: Save any creates seen during the preview into an import file to use with pulumi import
:returns: PreviewResult
"""
# Disable unused-argument because pylint doesn't understand we process them in _parse_extra_args
Expand All @@ -386,6 +388,10 @@ def preview(
args = ["preview"]
args.extend(extra_args)

if import_file is not None:
args.append("--import-file")
args.append(import_file)

if plan is not None:
args.append("--save-plan")
args.append(plan)
Expand Down

0 comments on commit b57c60f

Please sign in to comment.