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 --version flag to 'pulumi stack export' #3906

Merged
merged 4 commits into from
Feb 13, 2020

Conversation

chrsmith
Copy link
Contributor

Add --version flag to pulumi stack export, which will request that the backend export an older version of the checkpoint rather than whatever is the "latest".

This is implemented not by adding a new method to the backend.Backend interface, since we don't necessarily want to require this capability for all backends. (And would also cause some problems, such as missing data, for the filestate backend.) So I went with an approach where we extend the interface, and dynamically check if the backend supports SpecificDeploymentExporter. (If you are familiar with COM, this is kinda-sorta the IBackend2 type pattern.

Examples of common errors:

# httpstate backend
$ pulumi stack export --version asdf 
error: "asdf" is not a valid stack version. It should be a positive integer.
$ pulumi stack export --version 1000
error: [404] Not Found: Stack Version '1000' not found

# filestate backend
$ pulumi stack export --version 2
error: the current backend (Chriss-MBP.lan) does not provide the ability to export previous deployments

Fixes #1910

Copy link
Contributor

@jkisk jkisk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -189,6 +189,19 @@ type Backend interface {
CurrentUser() (string, error)
}

// SpecificDeploymentExporter is an interface that extends Backend, which adds the ability to export
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to extend Backend (it's generally idiomatic to keep interfaces as narrow as possible). LGTM otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return b.exportDeployment(ctx, stack.Ref(), nil /* latest */)
}

func (b *cloudBackend) ExportSpecificDeployment(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
func (b *cloudBackend) ExportSpecificDeployment(
func (b *cloudBackend) ExportDeploymentForVersion(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@chrsmith chrsmith force-pushed the chrsmith/1910/export-older-versions branch from f96dad8 to 7cf6e31 Compare February 13, 2020 17:11
// SpecificDeploymentExporter is an interface defining an additional capability of a Backend, specifically the
// ability to export a specific versions of a stack's deployment. This isn't a requirement for all backends and
// should be checked for dynamically.
type SpecificDeploymentExporter interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nit for consistency with the method name

Suggested change
type SpecificDeploymentExporter interface {
type VersionedDeploymentExporter interface {

Copy link
Member

@pgavlin pgavlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM aside from one v small nit

@chrsmith chrsmith merged commit ba046b0 into master Feb 13, 2020
@pulumi-bot pulumi-bot deleted the chrsmith/1910/export-older-versions branch February 13, 2020 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to export specific versions of a checkpoint
3 participants