This change does three major things: 1. Removes the ability to be logged into multiple clouds at the same time. Previously, we supported being logged into multiple clouds at the same time and the CLI would fan out requests and join responses when needed. In general, this was only useful for Pulumi employees that wanted run against multiple copies of the service (say production and staging) but overall was very confusing (for example in the old world a stack with the same identity could appear twice (since it was in two backends) which the CLI didn't handle very well). 2. Stops treating the "local" backend as a special thing, from the point of view of the CLI. Previouly we'd always connect to the local backend and merge that data with whatever was in clouds we were connected to. We had gestures like `--local` in `pulumi stack init` that meant "use the local mode". Instead, to use the local mode now you run `pulumi login --cloud-url local://` and then you are logged in the local backend. Since you can only ever be logged into a single backend, we can remove the `--local` and `--remote` flags from `pulumi stack init`, it just now requires you to be logged in and creates a stack in whatever back end you were logged into. When logging into the local backend, you are not prompted for an access key. 3. Prompt for login in places where you have to log in, if you are not already logged in.
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
|
|
|
|
package state
|
|
|
|
import (
|
|
"github.com/pulumi/pulumi/pkg/backend"
|
|
"github.com/pulumi/pulumi/pkg/tokens"
|
|
"github.com/pulumi/pulumi/pkg/workspace"
|
|
)
|
|
|
|
// Stack returns an stack name after ensuring the stack exists. When an empty stack name is passed, the
|
|
// "current" ambient stack is returned.
|
|
func Stack(name tokens.QName, b backend.Backend) (backend.Stack, error) {
|
|
if name == "" {
|
|
return CurrentStack(b)
|
|
}
|
|
|
|
return b.GetStack(name)
|
|
}
|
|
|
|
// CurrentStack reads the current stack and returns an instance connected to its backend provider.
|
|
func CurrentStack(backends backend.Backend) (backend.Stack, error) {
|
|
w, err := workspace.New()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
stackName := w.Settings().Stack
|
|
if stackName == "" {
|
|
return nil, nil
|
|
}
|
|
|
|
return Stack(stackName, backends)
|
|
}
|
|
|
|
// SetCurrentStack changes the current stack to the given stack name.
|
|
func SetCurrentStack(name tokens.QName) error {
|
|
// Switch the current workspace to that stack.
|
|
w, err := workspace.New()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
w.Settings().Stack = name
|
|
return w.Save()
|
|
}
|