pulumi/pkg/backend/stack.go
joeduffy 2eb86b24c2 Make some updates based on CR feedback
This change implements some feedback from @ellismg.

* Make backend.Stack an interface and let backends implement it,
  enabling dynamic type testing/casting to access information
  specific to that backend.  For instance, the cloud.Stack conveys
  the cloud URL, org name, and PPC name, for each stack.

* Similarly expose specialized backend.Backend interfaces,
  local.Backend and cloud.Backend, to convey specific information.

* Redo a bunch of the commands in terms of these.

* Keeping with this theme, turn the CreateStack options into an
  opaque interface{}, and let the specific backends expose their
  own structures with their own settings (like PPC name in cloud).

* Show both the org and PPC names in the cloud column printed in
  the stack ls command, in addition to the Pulumi Cloud URL.

Unrelated, but useful:

* Special case the 401 HTTP response and make a friendly error,
  to tell the developer they must use `pulumi login`.  This is
  better than tossing raw "401: Unauthorized" errors in their face.

* Change the "Updating stack '..' in the Pulumi Cloud" message to
  use the correct action verb ("Previewing", "Destroying", etc).
2017-12-03 08:10:50 -08:00

51 lines
2.1 KiB
Go

// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
package backend
import (
"github.com/pulumi/pulumi/pkg/engine"
"github.com/pulumi/pulumi/pkg/operations"
"github.com/pulumi/pulumi/pkg/resource/config"
"github.com/pulumi/pulumi/pkg/resource/deploy"
"github.com/pulumi/pulumi/pkg/tokens"
)
// Stack is a stack associated with a particular backend implementation.
type Stack interface {
Name() tokens.QName // this stack's name.
Config() config.Map // the current config map.
Snapshot() *deploy.Snapshot // the latest deployment snapshot.
Backend() Backend // the backend this stack belongs to.
Remove(force bool) (bool, error) // remove this stack.
Preview(debug bool, opts engine.PreviewOptions) error // preview changes to this stack.
Update(debug bool, opts engine.DeployOptions) error // update this stack.
Destroy(debug bool, opts engine.DestroyOptions) error // destroy this stack's resources.
GetLogs(query operations.LogQuery) ([]operations.LogEntry, error) // list log entries for this stack.
}
// RemoveStack returns the stack, or returns an error if it cannot.
func RemoveStack(s Stack, force bool) (bool, error) {
return s.Backend().RemoveStack(s.Name(), force)
}
// PreviewStack initiates a preview of the current workspace's contents.
func PreviewStack(s Stack, debug bool, opts engine.PreviewOptions) error {
return s.Backend().Preview(s.Name(), debug, opts)
}
// UpdateStack updates the target stack with the current workspace's contents (config and code).
func UpdateStack(s Stack, debug bool, opts engine.DeployOptions) error {
return s.Backend().Update(s.Name(), debug, opts)
}
// DestroyStack destroys all of this stack's resources.
func DestroyStack(s Stack, debug bool, opts engine.DestroyOptions) error {
return s.Backend().Destroy(s.Name(), debug, opts)
}
// GetStackLogs fetches a list of log entries for the current stack in the current backend.
func GetStackLogs(s Stack, query operations.LogQuery) ([]operations.LogEntry, error) {
return s.Backend().GetLogs(s.Name(), query)
}