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.
|
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
|
|
|
|
|
|
|
package local
|
|
|
|
|
|
|
|
import (
|
2018-03-22 18:42:43 +01:00
|
|
|
"bytes"
|
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
|
|
|
"fmt"
|
|
|
|
"io"
|
2018-04-24 23:23:08 +02:00
|
|
|
"math"
|
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
|
|
|
"os"
|
2018-01-31 22:07:40 +01:00
|
|
|
"sort"
|
2018-02-02 06:15:09 +01:00
|
|
|
"strconv"
|
2018-04-24 23:23:08 +02:00
|
|
|
"time"
|
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
|
|
|
|
2018-08-30 02:06:48 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/apitype"
|
2018-01-31 18:41:42 +01:00
|
|
|
"github.com/pulumi/pulumi/pkg/backend"
|
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/pulumi/pulumi/pkg/diag"
|
2018-01-31 22:07:40 +01:00
|
|
|
"github.com/pulumi/pulumi/pkg/diag/colors"
|
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/pulumi/pulumi/pkg/engine"
|
2018-02-04 10:18:06 +01:00
|
|
|
"github.com/pulumi/pulumi/pkg/resource"
|
2018-02-02 06:15:09 +01:00
|
|
|
"github.com/pulumi/pulumi/pkg/resource/deploy"
|
2018-01-18 23:33:03 +01:00
|
|
|
"github.com/pulumi/pulumi/pkg/util/cmdutil"
|
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/pulumi/pulumi/pkg/util/contract"
|
|
|
|
)
|
|
|
|
|
2018-04-10 21:03:11 +02:00
|
|
|
// DisplayEvents reads events from the `events` channel until it is closed, displaying each event as
|
|
|
|
// it comes in. Once all events have been read from the channel and displayed, it closes the `done`
|
|
|
|
// channel so the caller can await all the events being written.
|
|
|
|
func DisplayEvents(
|
2018-08-30 02:06:48 +02:00
|
|
|
op string, action apitype.UpdateKind, events <-chan engine.Event,
|
2018-04-10 21:03:11 +02:00
|
|
|
done chan<- bool, opts backend.DisplayOptions) {
|
|
|
|
|
|
|
|
if opts.DiffDisplay {
|
2018-08-30 02:06:48 +02:00
|
|
|
DisplayDiffEvents(op, action, events, done, opts)
|
2018-04-10 21:03:11 +02:00
|
|
|
} else {
|
2018-08-30 02:06:48 +02:00
|
|
|
DisplayProgressEvents(op, action, events, done, opts)
|
2018-04-10 21:03:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-24 23:23:08 +02:00
|
|
|
type nopSpinner struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *nopSpinner) Tick() {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *nopSpinner) Reset() {
|
|
|
|
}
|
|
|
|
|
2018-04-10 21:03:11 +02:00
|
|
|
// DisplayDiffEvents displays the engine events with the diff view.
|
2018-08-30 02:06:48 +02:00
|
|
|
func DisplayDiffEvents(op string, action apitype.UpdateKind,
|
2018-04-10 21:03:11 +02:00
|
|
|
events <-chan engine.Event, done chan<- bool, opts backend.DisplayOptions) {
|
|
|
|
|
2018-08-30 02:06:48 +02:00
|
|
|
prefix := fmt.Sprintf("%s%s...", cmdutil.EmojiOr("✨ ", "@ "), op)
|
2018-04-24 23:23:08 +02:00
|
|
|
|
|
|
|
var spinner cmdutil.Spinner
|
|
|
|
var ticker *time.Ticker
|
|
|
|
|
|
|
|
if opts.IsInteractive {
|
|
|
|
spinner, ticker = cmdutil.NewSpinnerAndTicker(prefix, nil, 8 /*timesPerSecond*/)
|
|
|
|
} else {
|
|
|
|
spinner = &nopSpinner{}
|
|
|
|
ticker = time.NewTicker(math.MaxInt64)
|
|
|
|
}
|
2018-01-18 23:33:03 +01:00
|
|
|
|
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
|
|
|
defer func() {
|
2018-02-16 03:22:17 +01:00
|
|
|
spinner.Reset()
|
2018-01-18 23:33:03 +01:00
|
|
|
ticker.Stop()
|
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
|
|
|
done <- true
|
|
|
|
}()
|
|
|
|
|
2018-03-31 21:08:48 +02:00
|
|
|
seen := make(map[resource.URN]engine.StepEventMetadata)
|
|
|
|
|
2018-01-18 23:33:03 +01:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ticker.C:
|
|
|
|
spinner.Tick()
|
|
|
|
case event := <-events:
|
2018-03-09 22:46:54 +01:00
|
|
|
spinner.Reset()
|
2018-03-22 18:42:43 +01:00
|
|
|
|
|
|
|
out := os.Stdout
|
|
|
|
if event.Type == engine.DiagEvent {
|
2018-01-18 23:33:03 +01:00
|
|
|
payload := event.Payload.(engine.DiagEventPayload)
|
|
|
|
if payload.Severity == diag.Error || payload.Severity == diag.Warning {
|
|
|
|
out = os.Stderr
|
|
|
|
}
|
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
|
|
|
}
|
2018-02-16 03:22:17 +01:00
|
|
|
|
2018-08-30 02:06:48 +02:00
|
|
|
msg := RenderDiffEvent(action, event, seen, opts)
|
2018-02-16 03:22:17 +01:00
|
|
|
if msg != "" && out != nil {
|
2018-03-14 20:01:22 +01:00
|
|
|
fprintIgnoreError(out, msg)
|
2018-02-16 03:22:17 +01:00
|
|
|
}
|
2018-03-22 18:42:43 +01:00
|
|
|
|
|
|
|
if event.Type == engine.CancelEvent {
|
|
|
|
return
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-31 22:07:40 +01:00
|
|
|
|
2018-08-30 02:06:48 +02:00
|
|
|
func RenderDiffEvent(action apitype.UpdateKind, event engine.Event,
|
|
|
|
seen map[resource.URN]engine.StepEventMetadata, opts backend.DisplayOptions) string {
|
2018-03-31 21:08:48 +02:00
|
|
|
|
2018-03-22 18:42:43 +01:00
|
|
|
switch event.Type {
|
|
|
|
case engine.CancelEvent:
|
|
|
|
return ""
|
|
|
|
case engine.PreludeEvent:
|
2018-04-10 21:03:11 +02:00
|
|
|
return renderPreludeEvent(event.Payload.(engine.PreludeEventPayload), opts)
|
2018-03-22 18:42:43 +01:00
|
|
|
case engine.SummaryEvent:
|
2018-08-30 02:06:48 +02:00
|
|
|
return renderSummaryEvent(action, event.Payload.(engine.SummaryEventPayload), opts)
|
2018-03-22 18:42:43 +01:00
|
|
|
case engine.ResourceOperationFailed:
|
2018-04-10 21:03:11 +02:00
|
|
|
return renderResourceOperationFailedEvent(event.Payload.(engine.ResourceOperationFailedPayload), opts)
|
2018-03-22 18:42:43 +01:00
|
|
|
case engine.ResourceOutputsEvent:
|
2018-04-10 21:03:11 +02:00
|
|
|
return renderResourceOutputsEvent(event.Payload.(engine.ResourceOutputsEventPayload), seen, opts)
|
2018-03-22 18:42:43 +01:00
|
|
|
case engine.ResourcePreEvent:
|
2018-04-10 21:03:11 +02:00
|
|
|
return renderResourcePreEvent(event.Payload.(engine.ResourcePreEventPayload), seen, opts)
|
2018-03-22 18:42:43 +01:00
|
|
|
case engine.StdoutColorEvent:
|
2018-04-10 21:03:11 +02:00
|
|
|
return renderStdoutColorEvent(event.Payload.(engine.StdoutEventPayload), opts)
|
2018-03-22 18:42:43 +01:00
|
|
|
case engine.DiagEvent:
|
2018-04-14 07:26:01 +02:00
|
|
|
return renderDiffDiagEvent(event.Payload.(engine.DiagEventPayload), opts)
|
2018-03-22 18:42:43 +01:00
|
|
|
default:
|
|
|
|
contract.Failf("unknown event type '%s'", event.Type)
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-14 07:26:01 +02:00
|
|
|
func renderDiffDiagEvent(payload engine.DiagEventPayload, opts backend.DisplayOptions) string {
|
2018-04-10 21:03:11 +02:00
|
|
|
if payload.Severity == diag.Debug && !opts.Debug {
|
2018-03-31 21:08:48 +02:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return opts.Color.Colorize(payload.Message)
|
|
|
|
}
|
|
|
|
|
2018-04-10 21:03:11 +02:00
|
|
|
func renderStdoutColorEvent(
|
|
|
|
payload engine.StdoutEventPayload, opts backend.DisplayOptions) string {
|
|
|
|
|
2018-03-31 21:08:48 +02:00
|
|
|
return opts.Color.Colorize(payload.Message)
|
|
|
|
}
|
|
|
|
|
2018-08-30 02:06:48 +02:00
|
|
|
func renderSummaryEvent(
|
|
|
|
action apitype.UpdateKind, event engine.SummaryEventPayload, opts backend.DisplayOptions) string {
|
2018-02-02 06:15:09 +01:00
|
|
|
changes := event.ResourceChanges
|
|
|
|
|
|
|
|
changeCount := 0
|
|
|
|
for op, c := range changes {
|
|
|
|
if op != deploy.OpSame {
|
|
|
|
changeCount += c
|
|
|
|
}
|
|
|
|
}
|
2018-09-02 20:26:39 +02:00
|
|
|
|
|
|
|
var actionVerbLabel string
|
|
|
|
if action == apitype.RefreshUpdate {
|
|
|
|
actionVerbLabel = "found during refresh"
|
|
|
|
} else if event.IsPreview {
|
|
|
|
actionVerbLabel = "previewed"
|
2018-02-02 06:15:09 +01:00
|
|
|
} else {
|
2018-09-02 20:26:39 +02:00
|
|
|
actionVerbLabel = "performed"
|
2018-02-02 06:15:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var changesLabel string
|
|
|
|
if changeCount == 0 {
|
|
|
|
changesLabel = "no"
|
2018-09-02 20:26:39 +02:00
|
|
|
|
|
|
|
if action != apitype.RefreshUpdate {
|
|
|
|
actionVerbLabel = "required"
|
|
|
|
}
|
2018-02-02 06:15:09 +01:00
|
|
|
} else {
|
|
|
|
changesLabel = strconv.Itoa(changeCount)
|
|
|
|
}
|
|
|
|
|
|
|
|
if changeCount > 0 || changes[deploy.OpSame] > 0 {
|
2018-09-02 20:26:39 +02:00
|
|
|
actionVerbLabel += ":"
|
2018-02-02 06:15:09 +01:00
|
|
|
}
|
|
|
|
|
2018-03-22 18:42:43 +01:00
|
|
|
out := &bytes.Buffer{}
|
2018-03-14 20:01:22 +01:00
|
|
|
fprintIgnoreError(out, opts.Color.Colorize(fmt.Sprintf("%vinfo%v: %v %v %v\n",
|
2018-09-02 20:26:39 +02:00
|
|
|
colors.SpecInfo, colors.Reset, changesLabel, plural("change", changeCount), actionVerbLabel)))
|
2018-02-02 06:15:09 +01:00
|
|
|
|
|
|
|
var planTo string
|
|
|
|
if event.IsPreview {
|
|
|
|
planTo = "to "
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now summarize all of the changes; we print sames a little differently.
|
|
|
|
for _, op := range deploy.StepOps {
|
|
|
|
if op != deploy.OpSame {
|
|
|
|
if c := changes[op]; c > 0 {
|
|
|
|
opDescription := string(op)
|
|
|
|
if !event.IsPreview {
|
|
|
|
opDescription = op.PastTense()
|
|
|
|
}
|
2018-03-14 20:01:22 +01:00
|
|
|
fprintIgnoreError(out, opts.Color.Colorize(fmt.Sprintf(" %v%v %v %v%v%v\n",
|
2018-02-02 06:15:09 +01:00
|
|
|
op.Prefix(), c, plural("resource", c), planTo, opDescription, colors.Reset)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-15 21:47:53 +02:00
|
|
|
|
2018-02-02 06:15:09 +01:00
|
|
|
if c := changes[deploy.OpSame]; c > 0 {
|
2018-03-14 20:01:22 +01:00
|
|
|
fprintfIgnoreError(out, " %v %v unchanged\n", c, plural("resource", c))
|
2018-02-02 06:15:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// For actual deploys, we print some additional summary information
|
|
|
|
if !event.IsPreview {
|
|
|
|
if changeCount > 0 {
|
2018-03-14 20:01:22 +01:00
|
|
|
fprintIgnoreError(out, opts.Color.Colorize(fmt.Sprintf("%vUpdate duration: %v%v\n",
|
2018-02-02 06:15:09 +01:00
|
|
|
colors.SpecUnimportant, event.Duration, colors.Reset)))
|
|
|
|
}
|
|
|
|
}
|
2018-03-22 18:42:43 +01:00
|
|
|
|
|
|
|
return out.String()
|
2018-02-02 06:15:09 +01:00
|
|
|
}
|
|
|
|
|
2018-04-10 21:03:11 +02:00
|
|
|
func renderPreludeEvent(event engine.PreludeEventPayload, opts backend.DisplayOptions) string {
|
2018-03-22 18:42:43 +01:00
|
|
|
out := &bytes.Buffer{}
|
|
|
|
|
2018-01-31 22:07:40 +01:00
|
|
|
if opts.ShowConfig {
|
2018-03-14 20:01:22 +01:00
|
|
|
fprintIgnoreError(out, opts.Color.Colorize(fmt.Sprintf("%vConfiguration:%v\n", colors.SpecUnimportant, colors.Reset)))
|
2018-01-31 22:07:40 +01:00
|
|
|
|
|
|
|
var keys []string
|
|
|
|
for key := range event.Config {
|
|
|
|
keys = append(keys, key)
|
|
|
|
}
|
|
|
|
sort.Strings(keys)
|
|
|
|
for _, key := range keys {
|
2018-03-14 20:01:22 +01:00
|
|
|
fprintfIgnoreError(out, " %v: %v\n", key, event.Config[key])
|
2018-01-31 22:07:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
action := "Previewing"
|
|
|
|
if !event.IsPreview {
|
|
|
|
action = "Performing"
|
|
|
|
}
|
|
|
|
|
2018-03-14 20:01:22 +01:00
|
|
|
fprintIgnoreError(out, opts.Color.Colorize(
|
|
|
|
fmt.Sprintf("%v%v changes:%v\n", colors.SpecUnimportant, action, colors.Reset)))
|
2018-03-22 18:42:43 +01:00
|
|
|
|
|
|
|
return out.String()
|
2018-01-31 22:07:40 +01:00
|
|
|
}
|
2018-02-02 06:15:09 +01:00
|
|
|
|
2018-04-10 21:03:11 +02:00
|
|
|
func renderResourceOperationFailedEvent(
|
2018-03-31 21:08:48 +02:00
|
|
|
payload engine.ResourceOperationFailedPayload, opts backend.DisplayOptions) string {
|
2018-02-04 10:18:06 +01:00
|
|
|
|
2018-03-10 00:43:16 +01:00
|
|
|
// It's not actually useful or interesting to print out any details about
|
|
|
|
// the resource state here, because we always assume that the resource state
|
|
|
|
// is unknown if an error occurs.
|
|
|
|
//
|
|
|
|
// In the future, once we get more fine-grained error messages from providers,
|
|
|
|
// we can provide useful diagnostics here.
|
2018-03-22 18:42:43 +01:00
|
|
|
|
|
|
|
return ""
|
2018-02-04 10:18:06 +01:00
|
|
|
}
|
|
|
|
|
2018-04-10 21:03:11 +02:00
|
|
|
func renderResourcePreEvent(
|
2018-03-31 21:08:48 +02:00
|
|
|
payload engine.ResourcePreEventPayload,
|
|
|
|
seen map[resource.URN]engine.StepEventMetadata,
|
|
|
|
opts backend.DisplayOptions) string {
|
|
|
|
|
|
|
|
seen[payload.Metadata.URN] = payload.Metadata
|
2018-08-23 02:52:46 +02:00
|
|
|
if payload.Metadata.Op == deploy.OpRefresh {
|
|
|
|
return ""
|
|
|
|
}
|
2018-03-31 21:08:48 +02:00
|
|
|
|
2018-03-22 18:42:43 +01:00
|
|
|
out := &bytes.Buffer{}
|
2018-03-31 21:08:48 +02:00
|
|
|
if shouldShow(payload.Metadata, opts) || isRootStack(payload.Metadata) {
|
|
|
|
indent := engine.GetIndent(payload.Metadata, seen)
|
|
|
|
summary := engine.GetResourcePropertiesSummary(payload.Metadata, indent)
|
2018-04-14 07:26:01 +02:00
|
|
|
details := engine.GetResourcePropertiesDetails(
|
2018-05-23 02:20:03 +02:00
|
|
|
payload.Metadata, indent, payload.Planning, opts.SummaryDiff, payload.Debug)
|
2018-03-31 21:08:48 +02:00
|
|
|
|
|
|
|
fprintIgnoreError(out, opts.Color.Colorize(summary))
|
2018-04-10 21:03:11 +02:00
|
|
|
fprintIgnoreError(out, opts.Color.Colorize(details))
|
2018-03-14 20:01:22 +01:00
|
|
|
fprintIgnoreError(out, opts.Color.Colorize(colors.Reset))
|
2018-02-04 10:18:06 +01:00
|
|
|
}
|
2018-03-22 18:42:43 +01:00
|
|
|
return out.String()
|
2018-02-04 10:18:06 +01:00
|
|
|
}
|
|
|
|
|
2018-04-10 21:03:11 +02:00
|
|
|
func renderResourceOutputsEvent(
|
2018-03-31 21:08:48 +02:00
|
|
|
payload engine.ResourceOutputsEventPayload,
|
|
|
|
seen map[resource.URN]engine.StepEventMetadata,
|
|
|
|
opts backend.DisplayOptions) string {
|
|
|
|
|
2018-03-22 18:42:43 +01:00
|
|
|
out := &bytes.Buffer{}
|
2018-04-10 21:03:11 +02:00
|
|
|
if shouldShow(payload.Metadata, opts) || isRootStack(payload.Metadata) {
|
2018-03-31 21:08:48 +02:00
|
|
|
indent := engine.GetIndent(payload.Metadata, seen)
|
2018-08-23 02:52:46 +02:00
|
|
|
|
|
|
|
if m, has := seen[payload.Metadata.URN]; has && m.Op == deploy.OpRefresh {
|
|
|
|
summary := engine.GetResourcePropertiesSummary(payload.Metadata, indent)
|
|
|
|
fprintIgnoreError(out, opts.Color.Colorize(summary))
|
|
|
|
}
|
|
|
|
|
2018-04-06 07:27:04 +02:00
|
|
|
text := engine.GetResourceOutputsPropertiesString(payload.Metadata, indent+1, payload.Planning, payload.Debug)
|
2018-03-31 21:08:48 +02:00
|
|
|
|
|
|
|
fprintIgnoreError(out, opts.Color.Colorize(text))
|
2018-02-04 10:18:06 +01:00
|
|
|
}
|
2018-03-22 18:42:43 +01:00
|
|
|
return out.String()
|
2018-02-04 10:18:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// isRootStack returns true if the step pertains to the rootmost stack component.
|
2018-03-31 21:08:48 +02:00
|
|
|
func isRootStack(step engine.StepEventMetadata) bool {
|
2018-04-10 21:03:11 +02:00
|
|
|
return isRootURN(step.URN)
|
|
|
|
}
|
|
|
|
|
|
|
|
func isRootURN(urn resource.URN) bool {
|
|
|
|
return urn != "" && urn.Type() == resource.RootStackType
|
2018-02-04 10:18:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// shouldShow returns true if a step should show in the output.
|
2018-03-31 21:08:48 +02:00
|
|
|
func shouldShow(step engine.StepEventMetadata, opts backend.DisplayOptions) bool {
|
2018-02-04 10:18:06 +01:00
|
|
|
// For certain operations, whether they are tracked is controlled by flags (to cut down on superfluous output).
|
|
|
|
if step.Op == deploy.OpSame {
|
|
|
|
// If the op is the same, it is possible that the resource's metadata changed. In that case, still show it.
|
|
|
|
if step.Old.Protect != step.New.Protect {
|
|
|
|
return true
|
|
|
|
}
|
2018-04-14 07:26:01 +02:00
|
|
|
return opts.ShowSameResources
|
2018-02-04 10:18:06 +01:00
|
|
|
}
|
2018-08-02 06:48:14 +02:00
|
|
|
|
2018-02-04 10:18:06 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-02-02 06:15:09 +01:00
|
|
|
func plural(s string, c int) string {
|
|
|
|
if c != 1 {
|
|
|
|
s += "s"
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
2018-03-14 20:01:22 +01:00
|
|
|
|
|
|
|
func fprintfIgnoreError(w io.Writer, format string, a ...interface{}) {
|
|
|
|
_, err := fmt.Fprintf(w, format, a...)
|
|
|
|
contract.IgnoreError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func fprintIgnoreError(w io.Writer, a ...interface{}) {
|
|
|
|
_, err := fmt.Fprint(w, a...)
|
|
|
|
contract.IgnoreError(err)
|
|
|
|
}
|