2018-05-22 21:43:36 +02:00
|
|
|
// Copyright 2016-2018, Pulumi Corporation.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2017-10-16 21:04:35 +02:00
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
Improve the overall cloud CLI experience
This improves the overall cloud CLI experience workflow.
Now whether a stack is local or cloud is inherent to the stack
itself. If you interact with a cloud stack, we transparently talk
to the cloud; if you interact with a local stack, we just do the
right thing, and perform all operations locally. Aside from sometimes
seeing a cloud emoji pop-up ☁️, the experience is quite similar.
For example, to initialize a new cloud stack, simply:
$ pulumi login
Logging into Pulumi Cloud: https://pulumi.com/
Enter Pulumi access token: <enter your token>
$ pulumi stack init my-cloud-stack
Note that you may log into a specific cloud if you'd like. For
now, this is just for our own testing purposes, but someday when we
support custom clouds (e.g., Enterprise), you can just say:
$ pulumi login --cloud-url https://corp.acme.my-ppc.net:9873
The cloud is now the default. If you instead prefer a "fire and
forget" style of stack, you can skip the login and pass `--local`:
$ pulumi stack init my-faf-stack --local
If you are logged in and run `pulumi`, we tell you as much:
$ pulumi
Usage:
pulumi [command]
// as before...
Currently logged into the Pulumi Cloud ☁️
https://pulumi.com/
And if you list your stacks, we tell you which one is local or not:
$ pulumi stack ls
NAME LAST UPDATE RESOURCE COUNT CLOUD URL
my-cloud-stack 2017-12-01 ... 3 https://pulumi.com/
my-faf-stack n/a 0 n/a
And `pulumi stack` by itself prints information like your cloud org,
PPC name, and so on, in addition to the usuals.
I shall write up more details and make sure to document these changes.
This change also fairly significantly refactors the layout of cloud
versus local logic, so that the cmd/ package is resonsible for CLI
things, and the new pkg/backend/ package is responsible for the
backends. The following is the overall resulting package architecture:
* The backend.Backend interface can be implemented to substitute
a new backend. This has operations to get and list stacks,
perform updates, and so on.
* The backend.Stack struct is a wrapper around a stack that has
or is being manipulated by a Backend. It resembles our existing
Stack notions in the engine, but carries additional metadata
about its source. Notably, it offers functions that allow
operations like updating and deleting on the Backend from which
it came.
* There is very little else in the pkg/backend/ package.
* A new package, pkg/backend/local/, encapsulates all local state
management for "fire and forget" scenarios. It simply implements
the above logic and contains anything specific to the local
experience.
* A peer package, pkg/backend/cloud/, encapsulates all logic
required for the cloud experience. This includes its subpackage
apitype/ which contains JSON schema descriptions required for
REST calls against the cloud backend. It also contains handy
functions to list which clouds we have authenticated with.
* A subpackage here, pkg/backend/state/, is not a provider at all.
Instead, it contains all of the state management functions that
are currently shared between local and cloud backends. This
includes configuration logic -- including encryption -- as well
as logic pertaining to which stacks are known to the workspace.
This addresses pulumi/pulumi#629 and pulumi/pulumi#494.
2017-12-02 16:29:46 +01:00
|
|
|
"github.com/pkg/errors"
|
2017-10-16 21:04:35 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2018-09-05 00:40:15 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/backend/display"
|
2017-10-16 21:04:35 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/util/cmdutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newStackInitCmd() *cobra.Command {
|
2019-05-07 01:01:47 +02:00
|
|
|
var secretsProvider string
|
2018-12-10 19:10:43 +01:00
|
|
|
var stackName string
|
|
|
|
|
2017-11-01 22:55:16 +01:00
|
|
|
cmd := &cobra.Command{
|
2019-02-13 07:53:05 +01:00
|
|
|
Use: "init [<org-name>/]<stack-name>",
|
Make some stack-related CLI improvements (#947)
This change includes a handful of stack-related CLI formatting
improvements that I've been noodling on in the background for a while,
based on things that tend to trip up demos and the inner loop workflow.
This includes:
* If `pulumi stack select` is run by itself, use an interactive
CLI menu to let the user select an existing stack, or choose to
create a new one. This looks as follows
$ pulumi stack select
Please choose a stack, or choose to create a new one:
abcdef
babblabblabble
> currentlyselected
defcon
<create a new stack>
and is navigated in the usual way (key up, down, enter).
* If a stack name is passed that does not exist, prompt the user
to ask whether s/he wants to create one on-demand. This hooks
interesting moments in time, like `pulumi stack select foo`,
and cuts down on the need to run additional commands.
* If a current stack is required, but none is currently selected,
then pop the same interactive menu shown above to select one.
Depending on the command being run, we may or may not show the
option to create a new stack (e.g., that doesn't make much sense
when you're running `pulumi destroy`, but might when you're
running `pulumi stack`). This again lets you do with a single
command what would have otherwise entailed an error with multiple
commands to recover from it.
* If you run `pulumi stack init` without any additional arguments,
we interactively prompt for the stack name. Before, we would
error and you'd then need to run `pulumi stack init <name>`.
* Colorize some things nicely; for example, now all prompts will
by default become bright white.
2018-02-17 00:03:54 +01:00
|
|
|
Args: cmdutil.MaximumNArgs(1),
|
2017-10-16 21:04:35 +02:00
|
|
|
Short: "Create an empty stack with the given name, ready for updates",
|
|
|
|
Long: "Create an empty stack with the given name, ready for updates\n" +
|
|
|
|
"\n" +
|
|
|
|
"This command creates an empty stack with the given name. It has no resources,\n" +
|
2018-10-09 00:34:57 +02:00
|
|
|
"but afterwards it can become the target of a deployment using the `update` command.\n" +
|
|
|
|
"\n" +
|
2019-08-12 12:49:22 +02:00
|
|
|
"To create a stack in an organization when logged in to the Pulumi service,\n" +
|
|
|
|
"prefix the stack name with the organization name and a slash (e.g. 'acmecorp/dev')\n" +
|
2019-08-16 21:53:02 +02:00
|
|
|
"\n" +
|
|
|
|
"By default, a stack created using the pulumi.com backend will use the pulumi.com secrets\n" +
|
|
|
|
"provider and a stack created using the local or cloud object storage backend will use the\n" +
|
|
|
|
"`passphrase` secrets provider. A different secrets provider can be selected by passing the\n" +
|
|
|
|
"`--secrets-provider` flag.\n" +
|
|
|
|
"\n" +
|
|
|
|
"To use the `passphrase` secrets provider with the pulumi.com backend, use:\n" +
|
|
|
|
"* `pulumi stack init --secrets-provider=passphrase`\n" +
|
|
|
|
"\n" +
|
|
|
|
"To use a cloud secrets provider with any backend, use one of the following:\n" +
|
|
|
|
"* `pulumi stack init --secrets-provider=\"awskms://alias/ExampleAlias?region=us-east-1\"`\n" +
|
|
|
|
"* `pulumi stack init --secrets-provider=\"awskms://1234abcd-12ab-34cd-56ef-1234567890ab?region=us-east-1\"`\n" +
|
|
|
|
"* `pulumi stack init --secrets-provider=\"azurekeyvault://mykeyvaultname.vault.azure.net/keys/mykeyname\"`\n" +
|
|
|
|
"* `pulumi stack init --secrets-provider=\"gcpkms://projects/<p>/locations/<l>/keyRings/<r>/cryptoKeys/<k>\"`\n" +
|
|
|
|
"* `pulumi stack init --secrets-provider=\"hashivault://mykey\"`",
|
2017-10-16 21:04:35 +02:00
|
|
|
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
|
2018-09-05 00:40:15 +02:00
|
|
|
opts := display.Options{
|
2018-07-07 06:30:00 +02:00
|
|
|
Color: cmdutil.GetGlobalColorization(),
|
|
|
|
}
|
|
|
|
|
|
|
|
b, err := currentBackend(opts)
|
2018-04-05 00:31:01 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-02-26 20:00:16 +01:00
|
|
|
|
Make some stack-related CLI improvements (#947)
This change includes a handful of stack-related CLI formatting
improvements that I've been noodling on in the background for a while,
based on things that tend to trip up demos and the inner loop workflow.
This includes:
* If `pulumi stack select` is run by itself, use an interactive
CLI menu to let the user select an existing stack, or choose to
create a new one. This looks as follows
$ pulumi stack select
Please choose a stack, or choose to create a new one:
abcdef
babblabblabble
> currentlyselected
defcon
<create a new stack>
and is navigated in the usual way (key up, down, enter).
* If a stack name is passed that does not exist, prompt the user
to ask whether s/he wants to create one on-demand. This hooks
interesting moments in time, like `pulumi stack select foo`,
and cuts down on the need to run additional commands.
* If a current stack is required, but none is currently selected,
then pop the same interactive menu shown above to select one.
Depending on the command being run, we may or may not show the
option to create a new stack (e.g., that doesn't make much sense
when you're running `pulumi destroy`, but might when you're
running `pulumi stack`). This again lets you do with a single
command what would have otherwise entailed an error with multiple
commands to recover from it.
* If you run `pulumi stack init` without any additional arguments,
we interactively prompt for the stack name. Before, we would
error and you'd then need to run `pulumi stack init <name>`.
* Colorize some things nicely; for example, now all prompts will
by default become bright white.
2018-02-17 00:03:54 +01:00
|
|
|
if len(args) > 0 {
|
2018-12-10 19:10:43 +01:00
|
|
|
if stackName != "" {
|
|
|
|
return errors.New("only one of --stack or argument stack name may be specified, not both")
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:37:52 +02:00
|
|
|
stackName = args[0]
|
2018-12-10 19:10:43 +01:00
|
|
|
}
|
|
|
|
|
2019-05-15 08:56:36 +02:00
|
|
|
// Validate secrets provider type
|
|
|
|
if err := validateSecretsProvider(secretsProvider); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-12-10 19:10:43 +01:00
|
|
|
if stackName == "" && cmdutil.Interactive() {
|
2019-08-12 12:49:22 +02:00
|
|
|
hint := "Please enter your desired stack name."
|
|
|
|
if b.SupportsOrganizations() {
|
|
|
|
hint += "\nTo create a stack in an organization, " +
|
|
|
|
"use the format <org-name>/<stack-name> (e.g. `acmecorp/dev`)"
|
|
|
|
}
|
|
|
|
name, nameErr := cmdutil.ReadConsole(hint)
|
2018-04-05 00:31:01 +02:00
|
|
|
if nameErr != nil {
|
|
|
|
return nameErr
|
Make some stack-related CLI improvements (#947)
This change includes a handful of stack-related CLI formatting
improvements that I've been noodling on in the background for a while,
based on things that tend to trip up demos and the inner loop workflow.
This includes:
* If `pulumi stack select` is run by itself, use an interactive
CLI menu to let the user select an existing stack, or choose to
create a new one. This looks as follows
$ pulumi stack select
Please choose a stack, or choose to create a new one:
abcdef
babblabblabble
> currentlyselected
defcon
<create a new stack>
and is navigated in the usual way (key up, down, enter).
* If a stack name is passed that does not exist, prompt the user
to ask whether s/he wants to create one on-demand. This hooks
interesting moments in time, like `pulumi stack select foo`,
and cuts down on the need to run additional commands.
* If a current stack is required, but none is currently selected,
then pop the same interactive menu shown above to select one.
Depending on the command being run, we may or may not show the
option to create a new stack (e.g., that doesn't make much sense
when you're running `pulumi destroy`, but might when you're
running `pulumi stack`). This again lets you do with a single
command what would have otherwise entailed an error with multiple
commands to recover from it.
* If you run `pulumi stack init` without any additional arguments,
we interactively prompt for the stack name. Before, we would
error and you'd then need to run `pulumi stack init <name>`.
* Colorize some things nicely; for example, now all prompts will
by default become bright white.
2018-02-17 00:03:54 +01:00
|
|
|
}
|
2018-04-18 01:37:52 +02:00
|
|
|
stackName = name
|
Make some stack-related CLI improvements (#947)
This change includes a handful of stack-related CLI formatting
improvements that I've been noodling on in the background for a while,
based on things that tend to trip up demos and the inner loop workflow.
This includes:
* If `pulumi stack select` is run by itself, use an interactive
CLI menu to let the user select an existing stack, or choose to
create a new one. This looks as follows
$ pulumi stack select
Please choose a stack, or choose to create a new one:
abcdef
babblabblabble
> currentlyselected
defcon
<create a new stack>
and is navigated in the usual way (key up, down, enter).
* If a stack name is passed that does not exist, prompt the user
to ask whether s/he wants to create one on-demand. This hooks
interesting moments in time, like `pulumi stack select foo`,
and cuts down on the need to run additional commands.
* If a current stack is required, but none is currently selected,
then pop the same interactive menu shown above to select one.
Depending on the command being run, we may or may not show the
option to create a new stack (e.g., that doesn't make much sense
when you're running `pulumi destroy`, but might when you're
running `pulumi stack`). This again lets you do with a single
command what would have otherwise entailed an error with multiple
commands to recover from it.
* If you run `pulumi stack init` without any additional arguments,
we interactively prompt for the stack name. Before, we would
error and you'd then need to run `pulumi stack init <name>`.
* Colorize some things nicely; for example, now all prompts will
by default become bright white.
2018-02-17 00:03:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if stackName == "" {
|
|
|
|
return errors.New("missing stack name")
|
2017-10-16 21:04:35 +02:00
|
|
|
}
|
|
|
|
|
2018-04-20 08:16:07 +02:00
|
|
|
stackRef, err := b.ParseStackReference(stackName)
|
2018-04-18 01:37:52 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-10-24 22:50:35 +02:00
|
|
|
var createOpts interface{} // Backend-specific config options, none currently.
|
2019-05-07 01:01:47 +02:00
|
|
|
_, err = createStack(b, stackRef, createOpts, true /*setCurrent*/, secretsProvider)
|
Make some stack-related CLI improvements (#947)
This change includes a handful of stack-related CLI formatting
improvements that I've been noodling on in the background for a while,
based on things that tend to trip up demos and the inner loop workflow.
This includes:
* If `pulumi stack select` is run by itself, use an interactive
CLI menu to let the user select an existing stack, or choose to
create a new one. This looks as follows
$ pulumi stack select
Please choose a stack, or choose to create a new one:
abcdef
babblabblabble
> currentlyselected
defcon
<create a new stack>
and is navigated in the usual way (key up, down, enter).
* If a stack name is passed that does not exist, prompt the user
to ask whether s/he wants to create one on-demand. This hooks
interesting moments in time, like `pulumi stack select foo`,
and cuts down on the need to run additional commands.
* If a current stack is required, but none is currently selected,
then pop the same interactive menu shown above to select one.
Depending on the command being run, we may or may not show the
option to create a new stack (e.g., that doesn't make much sense
when you're running `pulumi destroy`, but might when you're
running `pulumi stack`). This again lets you do with a single
command what would have otherwise entailed an error with multiple
commands to recover from it.
* If you run `pulumi stack init` without any additional arguments,
we interactively prompt for the stack name. Before, we would
error and you'd then need to run `pulumi stack init <name>`.
* Colorize some things nicely; for example, now all prompts will
by default become bright white.
2018-02-17 00:03:54 +01:00
|
|
|
return err
|
2017-10-16 21:04:35 +02:00
|
|
|
}),
|
|
|
|
}
|
2018-12-10 19:10:43 +01:00
|
|
|
cmd.PersistentFlags().StringVarP(
|
|
|
|
&stackName, "stack", "s", "", "The name of the stack to create")
|
2019-05-07 01:01:47 +02:00
|
|
|
cmd.PersistentFlags().StringVar(
|
2019-05-15 08:56:36 +02:00
|
|
|
&secretsProvider, "secrets-provider", "default", "The type of the provider that should be used to encrypt and "+
|
2019-08-16 21:53:02 +02:00
|
|
|
"decrypt secrets (possible choices: default, passphrase, awskms, azurekeyvault, gcpkms, hashivault)")
|
2017-10-27 07:14:56 +02:00
|
|
|
return cmd
|
|
|
|
}
|