command/meta: add -shadow flag to disable shadow graph

Since it is still very much possible for this to cause problems, this
can be used to disable the shadow graph. We'll purposely not document
this since the goal is to remove this flag as we become more confident
with it.
This commit is contained in:
Mitchell Hashimoto 2016-10-21 14:25:05 -07:00
parent dcbcde4b82
commit ae4f79e3b6
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 19 additions and 1 deletions

View File

@ -63,10 +63,13 @@ type Meta struct {
// //
// parallelism is used to control the number of concurrent operations // parallelism is used to control the number of concurrent operations
// allowed when walking the graph // allowed when walking the graph
//
// shadow is used to enable/disable the shadow graph
statePath string statePath string
stateOutPath string stateOutPath string
backupPath string backupPath string
parallelism int parallelism int
shadow bool
} }
// initStatePaths is used to initialize the default values for // initStatePaths is used to initialize the default values for
@ -312,6 +315,7 @@ func (m *Meta) contextOpts() *terraform.ContextOpts {
opts.Variables = vs opts.Variables = vs
opts.Targets = m.targets opts.Targets = m.targets
opts.UIInput = m.UIInput() opts.UIInput = m.UIInput()
opts.Shadow = m.shadow
return &opts return &opts
} }
@ -328,6 +332,9 @@ func (m *Meta) flagSet(n string) *flag.FlagSet {
f.Var((*FlagKVFile)(&m.autoVariables), m.autoKey, "variable file") f.Var((*FlagKVFile)(&m.autoVariables), m.autoKey, "variable file")
} }
// Advanced (don't need documentation, or unlikely to be set)
f.BoolVar(&m.shadow, "shadow", true, "shadow graph")
// Experimental features // Experimental features
f.BoolVar(&terraform.X_newApply, "Xnew-apply", false, "experiment: new apply") f.BoolVar(&terraform.X_newApply, "Xnew-apply", false, "experiment: new apply")

View File

@ -70,6 +70,7 @@ type ContextOpts struct {
StateFutureAllowed bool StateFutureAllowed bool
Providers map[string]ResourceProviderFactory Providers map[string]ResourceProviderFactory
Provisioners map[string]ResourceProvisionerFactory Provisioners map[string]ResourceProvisionerFactory
Shadow bool
Targets []string Targets []string
Variables map[string]interface{} Variables map[string]interface{}
@ -93,6 +94,7 @@ type Context struct {
hooks []Hook hooks []Hook
module *module.Tree module *module.Tree
sh *stopHook sh *stopHook
shadow bool
state *State state *State
stateLock sync.RWMutex stateLock sync.RWMutex
targets []string targets []string
@ -174,6 +176,7 @@ func NewContext(opts *ContextOpts) (*Context, error) {
diff: opts.Diff, diff: opts.Diff,
hooks: hooks, hooks: hooks,
module: opts.Module, module: opts.Module,
shadow: opts.Shadow,
state: state, state: state,
targets: opts.Targets, targets: opts.Targets,
uiInput: opts.UIInput, uiInput: opts.UIInput,
@ -695,13 +698,18 @@ func (c *Context) walk(
// If we have a shadow graph, walk that as well // If we have a shadow graph, walk that as well
var shadowCtx *Context var shadowCtx *Context
var shadowCloser Shadow var shadowCloser Shadow
if shadow != nil { if c.shadow && shadow != nil {
// Build the shadow context. In the process, override the real context // Build the shadow context. In the process, override the real context
// with the one that is wrapped so that the shadow context can verify // with the one that is wrapped so that the shadow context can verify
// the results of the real. // the results of the real.
realCtx, shadowCtx, shadowCloser = newShadowContext(c) realCtx, shadowCtx, shadowCloser = newShadowContext(c)
} }
// Just log this so we can see it in a debug log
if !c.shadow {
log.Printf("[WARN] terraform: shadow graph disabled")
}
// Build the real graph walker // Build the real graph walker
log.Printf("[DEBUG] Starting graph walk: %s", operation.String()) log.Printf("[DEBUG] Starting graph walk: %s", operation.String())
walker := &ContextGraphWalker{Context: realCtx, Operation: operation} walker := &ContextGraphWalker{Context: realCtx, Operation: operation}

View File

@ -68,6 +68,9 @@ func TestNewContextState(t *testing.T) {
} }
func testContext2(t *testing.T, opts *ContextOpts) *Context { func testContext2(t *testing.T, opts *ContextOpts) *Context {
// Enable the shadow graph
opts.Shadow = true
ctx, err := NewContext(opts) ctx, err := NewContext(opts)
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)