Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for --import-file when using the Automation API #16071

Merged
merged 7 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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