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-08-30 03:24:12 +02:00
|
|
|
|
2017-08-23 01:56:15 +02:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2018-07-20 20:55:26 +02:00
|
|
|
"bytes"
|
|
|
|
"fmt"
|
2017-12-12 21:31:09 +01:00
|
|
|
"os"
|
2017-08-23 01:56:15 +02:00
|
|
|
|
2018-07-12 06:20:26 +02:00
|
|
|
"github.com/golang/glog"
|
2018-02-19 19:58:03 +01:00
|
|
|
"github.com/opentracing/opentracing-go"
|
2017-08-23 01:56:15 +02:00
|
|
|
"github.com/pkg/errors"
|
2018-02-19 19:58:03 +01:00
|
|
|
"github.com/pulumi/pulumi/pkg/diag"
|
2018-07-20 20:55:26 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/diag/colors"
|
2017-09-22 04:18:21 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/resource"
|
|
|
|
"github.com/pulumi/pulumi/pkg/resource/deploy"
|
|
|
|
"github.com/pulumi/pulumi/pkg/resource/plugin"
|
|
|
|
"github.com/pulumi/pulumi/pkg/tokens"
|
|
|
|
"github.com/pulumi/pulumi/pkg/util/contract"
|
2018-03-13 00:27:39 +01:00
|
|
|
"github.com/pulumi/pulumi/pkg/workspace"
|
2017-08-23 01:56:15 +02:00
|
|
|
)
|
|
|
|
|
2018-02-19 19:58:03 +01:00
|
|
|
// ProjectInfoContext returns information about the current project, including its pwd, main, and plugin context.
|
2018-04-26 02:20:08 +02:00
|
|
|
func ProjectInfoContext(projinfo *Projinfo, config plugin.ConfigSource, pluginEvents plugin.Events,
|
|
|
|
diag diag.Sink, tracingSpan opentracing.Span) (string, string, *plugin.Context, error) {
|
2018-02-19 19:58:03 +01:00
|
|
|
contract.Require(projinfo != nil, "projinfo")
|
|
|
|
|
|
|
|
// If the package contains an override for the main entrypoint, use it.
|
|
|
|
pwd, main, err := projinfo.GetPwdMain()
|
|
|
|
if err != nil {
|
|
|
|
return "", "", nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a context for plugins.
|
2018-06-25 07:47:54 +02:00
|
|
|
ctx, err := plugin.NewContext(diag, nil, config, pluginEvents, pwd, projinfo.Proj.RuntimeInfo.Options(), tracingSpan)
|
2018-02-19 19:58:03 +01:00
|
|
|
if err != nil {
|
|
|
|
return "", "", nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return pwd, main, ctx, nil
|
|
|
|
}
|
|
|
|
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
// newPlanContext creates a context for a subsequent planning operation. Callers must call Close on the
|
|
|
|
// resulting context object once they have completed the associated planning operation.
|
2018-05-05 02:01:35 +02:00
|
|
|
func newPlanContext(u UpdateInfo, opName string, parentSpan opentracing.SpanContext) (*planContext, error) {
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
contract.Require(u != nil, "u")
|
|
|
|
|
|
|
|
// Create a root span for the operation
|
2018-05-05 02:01:35 +02:00
|
|
|
opts := []opentracing.StartSpanOption{}
|
|
|
|
if opName != "" {
|
|
|
|
opts = append(opts, opentracing.Tag{Key: "operation", Value: opName})
|
|
|
|
}
|
|
|
|
if parentSpan != nil {
|
|
|
|
opts = append(opts, opentracing.ChildOf(parentSpan))
|
|
|
|
}
|
|
|
|
tracingSpan := opentracing.StartSpan("pulumi-plan", opts...)
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
|
|
|
|
return &planContext{
|
2018-04-17 08:04:56 +02:00
|
|
|
Update: u,
|
|
|
|
TracingSpan: tracingSpan,
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type planContext struct {
|
2018-04-17 08:04:56 +02:00
|
|
|
Update UpdateInfo // The update being processed.
|
|
|
|
TracingSpan opentracing.Span // An OpenTracing span to parent plan operations within.
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *planContext) Close() {
|
|
|
|
ctx.TracingSpan.Finish()
|
|
|
|
}
|
|
|
|
|
|
|
|
// planOptions includes a full suite of options for performing a plan and/or deploy operation.
|
|
|
|
type planOptions struct {
|
|
|
|
UpdateOptions
|
|
|
|
|
|
|
|
// SourceFunc is a factory that returns an EvalSource to use during planning. This is the thing that
|
|
|
|
// creates resources to compare against the current checkpoint state (e.g., by evaluating a program, etc).
|
|
|
|
SourceFunc planSourceFunc
|
|
|
|
|
2018-05-18 23:58:06 +02:00
|
|
|
SkipOutputs bool // true if we we should skip printing outputs separately.
|
|
|
|
DOT bool // true if we should print the DOT file for this plan.
|
|
|
|
Events eventEmitter // the channel to write events from the engine to.
|
|
|
|
Diag diag.Sink // the sink to use for diag'ing.
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// planSourceFunc is a callback that will be used to prepare for, and evaluate, the "new" state for a stack.
|
2018-04-14 07:26:01 +02:00
|
|
|
type planSourceFunc func(
|
|
|
|
opts planOptions, proj *workspace.Project, pwd, main string,
|
|
|
|
target *deploy.Target, plugctx *plugin.Context, dryRun bool) (deploy.Source, error)
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
|
2017-08-23 01:56:15 +02:00
|
|
|
// plan just uses the standard logic to parse arguments, options, and to create a snapshot and plan.
|
2018-05-18 23:58:06 +02:00
|
|
|
func plan(ctx *Context, info *planContext, opts planOptions, dryRun bool) (*planResult, error) {
|
|
|
|
contract.Assert(info != nil)
|
|
|
|
contract.Assert(info.Update != nil)
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
contract.Assert(opts.SourceFunc != nil)
|
2017-08-23 01:56:15 +02:00
|
|
|
|
2018-05-18 23:58:06 +02:00
|
|
|
// If this isn't a dry run, we will need to record plugin events, so that we persist them in the checkpoint. If
|
|
|
|
// we're just doing a dry run, we don't actually need to persist anything (and indeed trying to do so would fail).
|
|
|
|
var pluginEvents plugin.Events
|
|
|
|
if !dryRun {
|
|
|
|
pluginEvents = &pluginActions{ctx}
|
|
|
|
}
|
|
|
|
|
2018-01-08 22:01:40 +01:00
|
|
|
// First, load the package metadata and the deployment target in preparation for executing the package's program
|
2018-02-19 19:58:03 +01:00
|
|
|
// and creating resources. This includes fetching its pwd and main overrides.
|
2018-05-18 23:58:06 +02:00
|
|
|
proj, target := info.Update.GetProject(), info.Update.GetTarget()
|
2018-02-14 22:56:16 +01:00
|
|
|
contract.Assert(proj != nil)
|
2018-01-08 22:01:40 +01:00
|
|
|
contract.Assert(target != nil)
|
2018-05-18 23:58:06 +02:00
|
|
|
projinfo := &Projinfo{Proj: proj, Root: info.Update.GetRoot()}
|
|
|
|
pwd, main, plugctx, err := ProjectInfoContext(projinfo, target, pluginEvents, opts.Diag, info.TracingSpan)
|
2017-12-12 21:31:09 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
// Now create the state source. This may issue an error if it can't create the source. This entails,
|
|
|
|
// for example, loading any plugins which will be required to execute a program, among other things.
|
2018-04-14 07:26:01 +02:00
|
|
|
source, err := opts.SourceFunc(opts, proj, pwd, main, target, plugctx, dryRun)
|
2018-02-06 18:57:32 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-08-23 01:56:15 +02:00
|
|
|
// If there are any analyzers in the project file, add them.
|
|
|
|
var analyzers []tokens.QName
|
2018-02-14 22:56:16 +01:00
|
|
|
if as := projinfo.Proj.Analyzers; as != nil {
|
2017-08-23 01:56:15 +02:00
|
|
|
for _, a := range *as {
|
|
|
|
analyzers = append(analyzers, a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append any analyzers from the command line.
|
|
|
|
for _, a := range opts.Analyzers {
|
|
|
|
analyzers = append(analyzers, tokens.QName(a))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a plan; this API handles all interesting cases (create, update, delete).
|
2018-04-14 07:26:01 +02:00
|
|
|
plan := deploy.NewPlan(plugctx, target, target.Snapshot, source, analyzers, dryRun)
|
2017-08-23 01:56:15 +02:00
|
|
|
return &planResult{
|
2018-05-18 23:58:06 +02:00
|
|
|
Ctx: info,
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
Plugctx: plugctx,
|
2017-10-05 23:08:46 +02:00
|
|
|
Plan: plan,
|
|
|
|
Options: opts,
|
2017-08-23 01:56:15 +02:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type planResult struct {
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
Ctx *planContext // plan context information.
|
|
|
|
Plugctx *plugin.Context // the context containing plugins and their state.
|
2017-09-17 17:10:46 +02:00
|
|
|
Plan *deploy.Plan // the plan created by this command.
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
Options planOptions // the options used during planning.
|
2017-09-17 17:10:46 +02:00
|
|
|
}
|
|
|
|
|
2017-12-12 21:31:09 +01:00
|
|
|
// Chdir changes the directory so that all operations from now on are relative to the project we are working with.
|
|
|
|
// It returns a function that, when run, restores the old working directory.
|
|
|
|
func (res *planResult) Chdir() (func(), error) {
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
pwd := res.Plugctx.Pwd
|
|
|
|
if pwd == "" {
|
2017-12-12 21:31:09 +01:00
|
|
|
return func() {}, nil
|
|
|
|
}
|
|
|
|
oldpwd, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
if err = os.Chdir(pwd); err != nil {
|
2017-12-12 21:31:09 +01:00
|
|
|
return nil, errors.Wrapf(err, "could not change to the project working directory")
|
|
|
|
}
|
|
|
|
return func() {
|
|
|
|
// Restore the working directory after planning completes.
|
|
|
|
cderr := os.Chdir(oldpwd)
|
|
|
|
contract.IgnoreError(cderr)
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2017-10-02 23:26:51 +02:00
|
|
|
// Walk enumerates all steps in the plan, calling out to the provided action at each step. It returns four things: the
|
|
|
|
// resulting Snapshot, no matter whether an error occurs or not; an error, if something went wrong; the step that
|
|
|
|
// failed, if the error is non-nil; and finally the state of the resource modified in the failing step.
|
2018-04-20 03:59:14 +02:00
|
|
|
func (res *planResult) Walk(ctx *Context, events deploy.Events, preview bool) (deploy.PlanSummary,
|
Bring back component outputs
This change brings back component outputs to the overall system again.
In doing so, it generally overhauls the way we do resource RPCs a bit:
* Instead of RegisterResource and CompleteResource, we call these
BeginRegisterResource and EndRegisterResource, which begins to model
these as effectively "asynchronous" resource requests. This should also
help with parallelism (https://github.com/pulumi/pulumi/issues/106).
* Flip the CLI/engine a little on its head. Rather than it driving the
planning and deployment process, we move more to a model where it
simply observes it. This is done by implementing an event handler
interface with three events: OnResourceStepPre, OnResourceStepPost,
and OnResourceComplete. The first two are invoked immediately before
and after any step operation, and the latter is invoked whenever a
EndRegisterResource comes in. The reason for the asymmetry here is
that the checkpointing logic in the deployment engine is largely
untouched (intentionally, as this is a sensitive part of the system),
and so the "begin"/"end" nature doesn't flow through faithfully.
* Also make the engine more event-oriented in its terminology and the
way it handles the incoming BeginRegisterResource and
EndRegisterResource events from the language host. This is the first
step down a long road of incrementally refactoring the engine to work
this way, a necessary prerequisite for parallelism.
2017-11-29 16:42:14 +01:00
|
|
|
deploy.Step, resource.Status, error) {
|
2017-09-17 17:10:46 +02:00
|
|
|
opts := deploy.Options{
|
Bring back component outputs
This change brings back component outputs to the overall system again.
In doing so, it generally overhauls the way we do resource RPCs a bit:
* Instead of RegisterResource and CompleteResource, we call these
BeginRegisterResource and EndRegisterResource, which begins to model
these as effectively "asynchronous" resource requests. This should also
help with parallelism (https://github.com/pulumi/pulumi/issues/106).
* Flip the CLI/engine a little on its head. Rather than it driving the
planning and deployment process, we move more to a model where it
simply observes it. This is done by implementing an event handler
interface with three events: OnResourceStepPre, OnResourceStepPost,
and OnResourceComplete. The first two are invoked immediately before
and after any step operation, and the latter is invoked whenever a
EndRegisterResource comes in. The reason for the asymmetry here is
that the checkpointing logic in the deployment engine is largely
untouched (intentionally, as this is a sensitive part of the system),
and so the "begin"/"end" nature doesn't flow through faithfully.
* Also make the engine more event-oriented in its terminology and the
way it handles the incoming BeginRegisterResource and
EndRegisterResource events from the language host. This is the first
step down a long road of incrementally refactoring the engine to work
this way, a necessary prerequisite for parallelism.
2017-11-29 16:42:14 +01:00
|
|
|
Events: events,
|
2017-09-17 17:10:46 +02:00
|
|
|
Parallel: res.Options.Parallel,
|
|
|
|
}
|
2017-08-23 01:56:15 +02:00
|
|
|
|
2017-10-02 23:26:51 +02:00
|
|
|
// Fetch a plan iterator and keep walking it until we are done.
|
|
|
|
iter, err := res.Plan.Start(opts)
|
2017-08-23 01:56:15 +02:00
|
|
|
if err != nil {
|
2017-10-02 23:26:51 +02:00
|
|
|
return nil, nil, resource.StatusOK, err
|
2017-08-23 01:56:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
step, err := iter.Next()
|
|
|
|
if err != nil {
|
2018-04-20 03:59:14 +02:00
|
|
|
closeErr := iter.Close() // ignore close errors; the Next error trumps
|
|
|
|
contract.IgnoreError(closeErr)
|
2017-10-02 23:26:51 +02:00
|
|
|
return nil, nil, resource.StatusOK, err
|
2017-08-23 01:56:15 +02:00
|
|
|
}
|
|
|
|
|
2018-04-20 03:59:14 +02:00
|
|
|
// Iterate the plan in a goroutine while listening for termination.
|
|
|
|
var rst resource.Status
|
|
|
|
done := make(chan bool)
|
|
|
|
go func() {
|
|
|
|
defer func() {
|
|
|
|
// Close the iterator. If we have already observed another error, that error trumps the close error.
|
|
|
|
closeErr := iter.Close()
|
|
|
|
if err == nil {
|
|
|
|
err = closeErr
|
|
|
|
}
|
|
|
|
close(done)
|
|
|
|
}()
|
|
|
|
|
|
|
|
for step != nil {
|
|
|
|
// Check for cancellation and termination.
|
|
|
|
if cancelErr := ctx.Cancel.CancelErr(); cancelErr != nil {
|
|
|
|
rst, err = resource.StatusOK, cancelErr
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-20 20:55:26 +02:00
|
|
|
// Warn the user if they're not updating a resource whose initialization failed.
|
|
|
|
if step.Op() == deploy.OpSame && len(step.Old().InitErrors) > 0 {
|
|
|
|
indent := " "
|
|
|
|
|
|
|
|
// TODO: Move indentation to the display logic, instead of doing it ourselves.
|
|
|
|
var warning bytes.Buffer
|
|
|
|
warning.WriteString("This resource failed to initialize in a previous deployment. It is recommended\n")
|
|
|
|
warning.WriteString(indent + "to update it to fix these issues:\n")
|
|
|
|
for i, err := range step.Old().InitErrors {
|
|
|
|
warning.WriteString(colors.SpecImportant + indent + fmt.Sprintf(" - Problem #%d", i+1) +
|
|
|
|
colors.Reset + " " + err + "\n")
|
|
|
|
}
|
|
|
|
res.Options.Diag.Warningf(diag.RawMessage(step.URN(), warning.String()))
|
|
|
|
}
|
|
|
|
|
2018-04-20 03:59:14 +02:00
|
|
|
// Perform any per-step actions.
|
|
|
|
rst, err = iter.Apply(step, preview)
|
|
|
|
|
|
|
|
// If an error occurred, exit early.
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
contract.Assert(rst == resource.StatusOK)
|
|
|
|
|
|
|
|
step, err = iter.Next()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2017-08-23 01:56:15 +02:00
|
|
|
}
|
|
|
|
|
2018-04-20 03:59:14 +02:00
|
|
|
// Finally, return a summary and the resulting plan information.
|
|
|
|
rst, err = resource.StatusOK, nil
|
|
|
|
}()
|
2017-10-02 23:26:51 +02:00
|
|
|
|
2018-07-12 06:20:26 +02:00
|
|
|
// Asynchronously listen for cancellation, and deliver that signal to plan.
|
|
|
|
go func() {
|
|
|
|
select {
|
|
|
|
case <-ctx.Cancel.Canceled():
|
|
|
|
cancelErr := res.Plan.SignalCancellation()
|
|
|
|
if cancelErr != nil {
|
|
|
|
glog.V(3).Infof("Attempted to signal cancellation to resource providers, but failed: %s",
|
|
|
|
cancelErr.Error())
|
|
|
|
}
|
|
|
|
case <-done:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2018-04-20 03:59:14 +02:00
|
|
|
select {
|
|
|
|
case <-ctx.Cancel.Terminated():
|
|
|
|
return iter, step, rst, ctx.Cancel.TerminateErr()
|
|
|
|
|
|
|
|
case <-done:
|
|
|
|
return iter, step, rst, err
|
|
|
|
}
|
2017-10-02 23:26:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (res *planResult) Close() error {
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
return res.Plugctx.Close()
|
2017-10-02 23:26:51 +02:00
|
|
|
}
|
|
|
|
|
2018-01-20 21:15:28 +01:00
|
|
|
// printPlan prints the plan's result to the plan's Options.Events stream.
|
2018-04-20 03:59:14 +02:00
|
|
|
func printPlan(ctx *Context, result *planResult, dryRun bool) (ResourceChanges, error) {
|
2018-04-14 07:26:01 +02:00
|
|
|
result.Options.Events.preludeEvent(dryRun, result.Ctx.Update.GetTarget().Config)
|
2017-10-02 23:26:51 +02:00
|
|
|
|
2018-01-31 22:07:40 +01:00
|
|
|
// Walk the plan's steps and and pretty-print them out.
|
2018-05-18 23:58:06 +02:00
|
|
|
actions := newPlanActions(result.Options)
|
2018-04-30 19:27:04 +02:00
|
|
|
_, step, _, err := result.Walk(ctx, actions, true)
|
2017-10-02 23:26:51 +02:00
|
|
|
if err != nil {
|
2018-04-30 19:27:04 +02:00
|
|
|
var failedUrn resource.URN
|
|
|
|
if step != nil {
|
|
|
|
failedUrn = step.URN()
|
|
|
|
}
|
|
|
|
|
|
|
|
result.Options.Diag.Errorf(diag.Message(failedUrn, err.Error()))
|
2018-03-10 00:43:16 +01:00
|
|
|
return nil, errors.New("an error occurred while advancing the preview")
|
2017-08-23 01:56:15 +02:00
|
|
|
}
|
|
|
|
|
2018-02-02 06:15:09 +01:00
|
|
|
// Emit an event with a summary of operation counts.
|
2018-01-25 03:22:41 +01:00
|
|
|
changes := ResourceChanges(actions.Ops)
|
2018-03-05 20:39:50 +01:00
|
|
|
result.Options.Events.previewSummaryEvent(changes)
|
2018-01-25 03:22:41 +01:00
|
|
|
return changes, nil
|
2017-08-23 01:56:15 +02:00
|
|
|
}
|
|
|
|
|
2018-05-18 23:58:06 +02:00
|
|
|
type planActions struct {
|
|
|
|
Refresh bool
|
|
|
|
Ops map[deploy.StepOp]int
|
|
|
|
Opts planOptions
|
|
|
|
Seen map[resource.URN]deploy.Step
|
|
|
|
}
|
|
|
|
|
|
|
|
func newPlanActions(opts planOptions) *planActions {
|
|
|
|
return &planActions{
|
|
|
|
Ops: make(map[deploy.StepOp]int),
|
|
|
|
Opts: opts,
|
|
|
|
Seen: make(map[resource.URN]deploy.Step),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (acts *planActions) OnResourceStepPre(step deploy.Step) (interface{}, error) {
|
|
|
|
acts.Seen[step.URN()] = step
|
|
|
|
acts.Opts.Events.resourcePreEvent(step, true /*planning*/, acts.Opts.Debug)
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (acts *planActions) OnResourceStepPost(ctx interface{},
|
|
|
|
step deploy.Step, status resource.Status, err error) error {
|
|
|
|
assertSeen(acts.Seen, step)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
acts.Opts.Diag.Errorf(diag.GetPreviewFailedError(step.URN()), err)
|
|
|
|
} else {
|
|
|
|
// Track the operation if shown and/or if it is a logically meaningful operation.
|
|
|
|
if step.Logical() {
|
|
|
|
acts.Ops[step.Op()]++
|
|
|
|
}
|
|
|
|
|
|
|
|
_ = acts.OnResourceOutputs(step)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (acts *planActions) OnResourceOutputs(step deploy.Step) error {
|
|
|
|
assertSeen(acts.Seen, step)
|
|
|
|
|
|
|
|
// Print the resource outputs separately, unless this is a refresh in which case they are already printed.
|
|
|
|
if !acts.Opts.SkipOutputs {
|
|
|
|
acts.Opts.Events.resourceOutputsEvent(step, true /*planning*/, acts.Opts.Debug)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-02-03 01:02:50 +01:00
|
|
|
func assertSeen(seen map[resource.URN]deploy.Step, step deploy.Step) {
|
|
|
|
_, has := seen[step.URN()]
|
|
|
|
contract.Assertf(has, "URN '%v' had not been marked as seen", step.URN())
|
|
|
|
}
|