Commit graph

22 commits

Author SHA1 Message Date
joeduffy 5967259795 Add license headers 2018-05-22 15:02:47 -07:00
Joe Duffy 24b350ea40
Support -y as shorthand for --yes (#1340) 2018-05-08 09:55:08 -07:00
Pat Gavlin 97ace29ab1
Begin tracing Pulumi API calls. (#1330)
These changes enable tracing of Pulumi API calls.

The span with which to associate an API call is passed via a
`context.Context` parameter. This required plumbing a
`context.Context` parameter through a rather large number of APIs,
especially in the backend.

In general, all API calls are associated with a new root span that
exists for essentially the entire lifetime of an invocation of the
Pulumi CLI. There were a few places where the plumbing got a bit hairier
than I was willing to address with these changes; I've used
`context.Background()` in these instances. API calls that receive this
context will create new root spans, but will still be traced.
2018-05-07 18:23:03 -07:00
Matt Ellis 04e5dfde5f Address code review feedback 2018-04-20 01:31:14 -04:00
Matt Ellis c0b2c4f17f Introduce backend.StackReference
Long term, a stack name alone will not be sufficent to address a
stack. Introduce a new `backend.StackReference` interface that allows
each backend to give an opaque stack reference that can be used across
operations.
2018-04-18 04:54:02 -07:00
Pat Gavlin a23b10a9bf
Update the copyright end date to 2018. (#1068)
Just what it says on the tin.
2018-03-21 12:43:21 -07:00
Matt Ellis 207a9755d8 Rework configuration model
This change updates our configuration model to make it simpler to
understand by removing some features and changing how things are
persisted in files.

Notable changes:

- We've removed the notion of "workspace" vs "project"
  config. Now, configuration is always stored in a file next to
  `Pulumi.yaml` named `Pulumi.<stack-name>.yaml` (the same file we'd
  use for an other stack specific information we would need to persist
  in the future).
- We've removed the notion of project wide configuration. Every new
  stack gets a completely empty set of configuration and there's no
  way to share common values across stacks, instead the common value
  has to be set on each stack.

We retain some of the old code for the configuration system so we can
support upgrading a project in place. That will happen with the next
change.

This change fixes some issues and allows us to close some
others (since they are no longer possible).

Fixes #866
Closes #872
Closes #731
2018-02-28 17:30:50 -08:00
joeduffy c1752d357e Implement basic plugin management
This change implements basic plugin management, but we do not yet
actually use the plugins for anything (that comes next).

Plugins are stored in `~/.pulumi/plugins`, and are expected to be
in the format `pulumi-<KIND>-<NAME>-v<VERSION>[.exe]`.  The KIND is
one of `analyzer`, `language`, or `resource`, the NAME is a hyphen-
delimited name (e.g., `aws` or `foo-bar`), and VERSION is the
plugin's semantic version (e.g., `0.9.11`, `1.3.7-beta.a736cf`, etc).

This commit includes four new CLI commands:

* `pulumi plugin` is the top-level plugin command.  It does nothing
  but show the help text for associated child commands.

* `pulumi plugin install` can be used to install plugins manually.
  If run with no additional arguments, it will compute the set of
  plugins used by the current project, and download them all.  It
  may be run to explicitly download a single plugin, however, by
  invoking it as `pulumi plugin install KIND NAME VERSION`.  For
  example, `pulumi plugin install resource aws v0.9.11`.  By default,
  this command uses the cloud backend in the usual way to perform the
  download, although a separate URL may be given with --cloud-url,
  just like all other commands that interact with our backend service.

* `pulumi plugin ls` lists all plugins currently installed in the
  plugin cache.  It displays some useful statistics, like the size
  of the plugin, when it was installed, when it was last used, and
  so on.  It sorts the display alphabetically by plugin name, and
  for plugins with multiple versions, it shows the newest at the top.
  The command also summarizes how much disk space is currently being
  consumed by the plugin cache.  There are no filtering capabilities yet.

* `pulumi plugin prune` will delete plugins from the cache.  By
  default, when run with no arguments, it will delete everything.
  It may be run with additional arguments, KIND, NAME, and VERSION,
  each one getting more specific about what it will delete.  For
  instance, `pulumi plugin prune resource aws` will delete all AWS
  plugin versions, while `pulumi plugin prune resource aws <0.9`
  will delete all AWS plugins before version 0.9.  Unless --yes is
  passed, the command will confirm the deletion with a count of how
  many plugins will be affected by the command.

We do not yet actually download plugins on demand yet.  That will
come in a subsequent change.
2018-02-18 08:08:15 -08:00
Joe Duffy 776a76dffd
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-16 15:03:54 -08:00
Matt Ellis 78a2e39aab Exit when an error when confirmation is declined
Fixes #931
2018-02-16 00:32:24 -08:00
Matt Ellis 607b4990f5 Remove stack configuration when deleting a stack
When a stack is removed, we should delete any configuration it had
saved in either the Pulumi.yaml file or the workspace.

Fixes #772
2018-01-07 17:38:40 -08:00
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
joeduffy 1c4e41b916 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 14:34:42 -08:00
Matt Ellis 586c4cab69 Clear current stack after calling pulumi stack rm
Fixes #252
2017-11-30 11:21:48 -08:00
Matt Ellis 8f076b7cb3 Argument validation for CLI commands
Previously, we were inconsistent on how we handled argument validation
in the CLI. Many commands used cobra.Command's Args property to
provide a validator if they took arguments, but commands which did not
rarely used cobra.NoArgs to indicate this.

This change does two things:

1. Introduce `cmdutil.ArgsFunc` which works like `cmdutil.RunFunc`, it
wraps an existing cobra type and lets us control the behavior when an
arguments validator fails.

2. Ensure every command sets the Args property with an instance of
cmdutil.ArgsFunc. The cmdutil package defines wrapers for all the
cobra validators we are using, to prevent us from having to spell out
`cmduitl.ArgsFunc(...)` everywhere.

Fixes #588
2017-11-29 16:10:53 -08:00
Matt Ellis 07b4d9b36b Add Pulumi.com backend, unify cobra Commands
As part of the unification it became clear where we did not support
features that we had for the local backend. I opened issues and added
comments.
2017-11-02 11:19:00 -07:00
Matt Ellis 328734f874 Define backend interface, move local implementation behind it
This change introduces an abstraction for a `backend` which manages
the implementation of some CLI commands. As part of defining the
interface, we introduce a new local backend implementation that just
uses data local to the machine.

This will let us share argument parsing and some display information
between the local case and the pulumi.com case in the CLI. We can
continue to refine this interface over time (e.g. today we have the
implementation of the Destroy/Update/Preview actually writing output
but instead they should be returning strongly typed data that the CLI
knows how to display and is unified across Pulumi.com deploys and
local deploys).

But this is a good first step.
2017-11-02 11:19:00 -07:00
Chris Smith e0b67e1060 Address PR feedback 2017-11-02 11:19:00 -07:00
Chris Smith fc82e71f21 Update Stack tests 2017-11-02 11:19:00 -07:00
Chris Smith d66b792ecc Add 'stack rm' 2017-11-02 11:19:00 -07:00
Matt Ellis ade366544e Encrypt secrets in Pulumi.yaml
We now encrypt secrets at rest based on a key derived from a user
suplied passphrase.

The system is designed in a way such that we should be able to have a
different decrypter (either using a local key or some remote service
in the Pulumi.com case in the future).

Care is taken to ensure that we do not leak decrypted secrets into the
"info" section of the checkpoint file (since we currently store the
config there).

In addtion, secrets are "pay for play", a passphrase is only needed
when dealing with a value that's encrypted. If secure config values
are not used, `pulumi` will never prompt you for a
passphrase. Otherwise, we only prompt if we know we are going to need
to decrypt the value. For example, `pulumi config <key>` only prompts
if `<key>` is encrypted and `pulumi deploy` and friends only prompt if
you are targeting a stack that has secure configuration assoicated
with it.

Secure values show up as unecrypted config values inside the language
hosts and providers.
2017-10-24 16:48:12 -07:00
Matt Ellis 22c9e0471c Use Stack over Environment to describe a deployment target
Previously we used the word "Environment" as the term for a deployment
target, but since then we've started to use the term Stack. Adopt this
across the CLI.

From a user's point of view, there are a few changes:

1. The `env` verb has been renamed to `stack`
2. The `-e` and `--env` options to commands which operate on an
environment now take `-s` or `--stack` instead.
3. Becase of (2), the commands that used `-s` to display a summary now
only support passing the full option name (`--summary`).

On the local file system, we still store checkpoint data in the `env`
sub-folder under `.pulumi` (so we can reuse existing checkpoint files
that were written to the old folder)
2017-10-16 13:04:20 -07:00
Renamed from cmd/env_rm.go (Browse further)