terraform: Graph, Context, Plan all speak modules

This commit is contained in:
Mitchell Hashimoto 2014-09-22 15:37:29 -07:00
parent 1d106d3fa4
commit a32833af2c
6 changed files with 203 additions and 179 deletions

View File

@ -9,6 +9,7 @@ import (
"sync/atomic" "sync/atomic"
"github.com/hashicorp/terraform/config" "github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/config/module"
"github.com/hashicorp/terraform/depgraph" "github.com/hashicorp/terraform/depgraph"
"github.com/hashicorp/terraform/helper/multierror" "github.com/hashicorp/terraform/helper/multierror"
) )
@ -24,6 +25,7 @@ type genericWalkFunc func(*Resource) error
// Additionally, a context can be created from a Plan using Plan.Context. // Additionally, a context can be created from a Plan using Plan.Context.
type Context struct { type Context struct {
config *config.Config config *config.Config
module *module.Tree
diff *Diff diff *Diff
hooks []Hook hooks []Hook
state *State state *State
@ -42,9 +44,9 @@ type Context struct {
// ContextOpts are the user-creatable configuration structure to create // ContextOpts are the user-creatable configuration structure to create
// a context with NewContext. // a context with NewContext.
type ContextOpts struct { type ContextOpts struct {
Config *config.Config
Diff *Diff Diff *Diff
Hooks []Hook Hooks []Hook
Module *module.Tree
Parallelism int Parallelism int
State *State State *State
Providers map[string]ResourceProviderFactory Providers map[string]ResourceProviderFactory
@ -73,10 +75,15 @@ func NewContext(opts *ContextOpts) *Context {
} }
parCh := make(chan struct{}, par) parCh := make(chan struct{}, par)
var config *config.Config
if opts.Module != nil {
config = opts.Module.Config()
}
// Calculate all the default variables // Calculate all the default variables
defaultVars := make(map[string]string) defaultVars := make(map[string]string)
if opts.Config != nil { if config != nil {
for _, v := range opts.Config.Variables { for _, v := range config.Variables {
for k, val := range v.DefaultsMap() { for k, val := range v.DefaultsMap() {
defaultVars[k] = val defaultVars[k] = val
} }
@ -84,9 +91,10 @@ func NewContext(opts *ContextOpts) *Context {
} }
return &Context{ return &Context{
config: opts.Config, config: config,
diff: opts.Diff, diff: opts.Diff,
hooks: hooks, hooks: hooks,
module: opts.Module,
state: opts.State, state: opts.State,
providers: opts.Providers, providers: opts.Providers,
provisioners: opts.Provisioners, provisioners: opts.Provisioners,
@ -108,8 +116,8 @@ func (c *Context) Apply() (*State, error) {
defer c.releaseRun(v) defer c.releaseRun(v)
g, err := Graph(&GraphOpts{ g, err := Graph(&GraphOpts{
Config: c.config,
Diff: c.diff, Diff: c.diff,
Module: c.module,
Providers: c.providers, Providers: c.providers,
Provisioners: c.provisioners, Provisioners: c.provisioners,
State: c.state, State: c.state,
@ -172,7 +180,7 @@ func (c *Context) Plan(opts *PlanOpts) (*Plan, error) {
defer c.releaseRun(v) defer c.releaseRun(v)
g, err := Graph(&GraphOpts{ g, err := Graph(&GraphOpts{
Config: c.config, Module: c.module,
Providers: c.providers, Providers: c.providers,
Provisioners: c.provisioners, Provisioners: c.provisioners,
State: c.state, State: c.state,
@ -237,7 +245,7 @@ func (c *Context) Refresh() (*State, error) {
c.state = c.state.deepcopy() c.state = c.state.deepcopy()
g, err := Graph(&GraphOpts{ g, err := Graph(&GraphOpts{
Config: c.config, Module: c.module,
Providers: c.providers, Providers: c.providers,
Provisioners: c.provisioners, Provisioners: c.provisioners,
State: c.state, State: c.state,
@ -493,8 +501,8 @@ func (c *Context) computeResourceMultiVariable(
func (c *Context) graph() (*depgraph.Graph, error) { func (c *Context) graph() (*depgraph.Graph, error) {
return Graph(&GraphOpts{ return Graph(&GraphOpts{
Config: c.config,
Diff: c.diff, Diff: c.diff,
Module: c.module,
Providers: c.providers, Providers: c.providers,
Provisioners: c.provisioners, Provisioners: c.provisioners,
State: c.state, State: c.state,

View File

@ -9,9 +9,9 @@ import (
func TestContextGraph(t *testing.T) { func TestContextGraph(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
config := testConfig(t, "validate-good") m := testModule(t, "validate-good")
c := testContext(t, &ContextOpts{ c := testContext(t, &ContextOpts{
Config: config, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -31,9 +31,9 @@ func TestContextGraph(t *testing.T) {
func TestContextValidate(t *testing.T) { func TestContextValidate(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
config := testConfig(t, "validate-good") m := testModule(t, "validate-good")
c := testContext(t, &ContextOpts{ c := testContext(t, &ContextOpts{
Config: config, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -50,9 +50,9 @@ func TestContextValidate(t *testing.T) {
func TestContextValidate_badVar(t *testing.T) { func TestContextValidate_badVar(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
config := testConfig(t, "validate-bad-var") m := testModule(t, "validate-bad-var")
c := testContext(t, &ContextOpts{ c := testContext(t, &ContextOpts{
Config: config, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -69,7 +69,7 @@ func TestContextValidate_badVar(t *testing.T) {
func TestContextValidate_orphans(t *testing.T) { func TestContextValidate_orphans(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
config := testConfig(t, "validate-good") m := testModule(t, "validate-good")
state := &State{ state := &State{
Modules: []*ModuleState{ Modules: []*ModuleState{
&ModuleState{ &ModuleState{
@ -86,7 +86,7 @@ func TestContextValidate_orphans(t *testing.T) {
}, },
} }
c := testContext(t, &ContextOpts{ c := testContext(t, &ContextOpts{
Config: config, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -108,10 +108,10 @@ func TestContextValidate_orphans(t *testing.T) {
} }
func TestContextValidate_providerConfig_bad(t *testing.T) { func TestContextValidate_providerConfig_bad(t *testing.T) {
config := testConfig(t, "validate-bad-pc") m := testModule(t, "validate-bad-pc")
p := testProvider("aws") p := testProvider("aws")
c := testContext(t, &ContextOpts{ c := testContext(t, &ContextOpts{
Config: config, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -129,10 +129,10 @@ func TestContextValidate_providerConfig_bad(t *testing.T) {
} }
func TestContextValidate_providerConfig_badEmpty(t *testing.T) { func TestContextValidate_providerConfig_badEmpty(t *testing.T) {
config := testConfig(t, "validate-bad-pc-empty") m := testModule(t, "validate-bad-pc-empty")
p := testProvider("aws") p := testProvider("aws")
c := testContext(t, &ContextOpts{ c := testContext(t, &ContextOpts{
Config: config, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -150,10 +150,10 @@ func TestContextValidate_providerConfig_badEmpty(t *testing.T) {
} }
func TestContextValidate_providerConfig_good(t *testing.T) { func TestContextValidate_providerConfig_good(t *testing.T) {
config := testConfig(t, "validate-bad-pc") m := testModule(t, "validate-bad-pc")
p := testProvider("aws") p := testProvider("aws")
c := testContext(t, &ContextOpts{ c := testContext(t, &ContextOpts{
Config: config, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -169,10 +169,10 @@ func TestContextValidate_providerConfig_good(t *testing.T) {
} }
func TestContextValidate_resourceConfig_bad(t *testing.T) { func TestContextValidate_resourceConfig_bad(t *testing.T) {
config := testConfig(t, "validate-bad-rc") m := testModule(t, "validate-bad-rc")
p := testProvider("aws") p := testProvider("aws")
c := testContext(t, &ContextOpts{ c := testContext(t, &ContextOpts{
Config: config, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -190,10 +190,10 @@ func TestContextValidate_resourceConfig_bad(t *testing.T) {
} }
func TestContextValidate_resourceConfig_good(t *testing.T) { func TestContextValidate_resourceConfig_good(t *testing.T) {
config := testConfig(t, "validate-bad-rc") m := testModule(t, "validate-bad-rc")
p := testProvider("aws") p := testProvider("aws")
c := testContext(t, &ContextOpts{ c := testContext(t, &ContextOpts{
Config: config, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -209,9 +209,9 @@ func TestContextValidate_resourceConfig_good(t *testing.T) {
} }
func TestContextValidate_requiredVar(t *testing.T) { func TestContextValidate_requiredVar(t *testing.T) {
config := testConfig(t, "validate-required-var") m := testModule(t, "validate-required-var")
c := testContext(t, &ContextOpts{ c := testContext(t, &ContextOpts{
Config: config, Module: m,
}) })
w, e := c.Validate() w, e := c.Validate()
@ -224,11 +224,11 @@ func TestContextValidate_requiredVar(t *testing.T) {
} }
func TestContextValidate_provisionerConfig_bad(t *testing.T) { func TestContextValidate_provisionerConfig_bad(t *testing.T) {
config := testConfig(t, "validate-bad-prov-conf") m := testModule(t, "validate-bad-prov-conf")
p := testProvider("aws") p := testProvider("aws")
pr := testProvisioner() pr := testProvisioner()
c := testContext(t, &ContextOpts{ c := testContext(t, &ContextOpts{
Config: config, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -249,7 +249,7 @@ func TestContextValidate_provisionerConfig_bad(t *testing.T) {
} }
func TestContextValidate_provisionerConfig_good(t *testing.T) { func TestContextValidate_provisionerConfig_good(t *testing.T) {
config := testConfig(t, "validate-bad-prov-conf") m := testModule(t, "validate-bad-prov-conf")
p := testProvider("aws") p := testProvider("aws")
pr := testProvisioner() pr := testProvisioner()
pr.ValidateFn = func(c *ResourceConfig) ([]string, []error) { pr.ValidateFn = func(c *ResourceConfig) ([]string, []error) {
@ -259,7 +259,7 @@ func TestContextValidate_provisionerConfig_good(t *testing.T) {
return nil, nil return nil, nil
} }
c := testContext(t, &ContextOpts{ c := testContext(t, &ContextOpts{
Config: config, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -279,9 +279,9 @@ func TestContextValidate_provisionerConfig_good(t *testing.T) {
func TestContextValidate_selfRef(t *testing.T) { func TestContextValidate_selfRef(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
config := testConfig(t, "validate-self-ref") m := testModule(t, "validate-self-ref")
c := testContext(t, &ContextOpts{ c := testContext(t, &ContextOpts{
Config: config, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -298,9 +298,9 @@ func TestContextValidate_selfRef(t *testing.T) {
func TestContextValidate_selfRefMulti(t *testing.T) { func TestContextValidate_selfRefMulti(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
config := testConfig(t, "validate-self-ref-multi") m := testModule(t, "validate-self-ref-multi")
c := testContext(t, &ContextOpts{ c := testContext(t, &ContextOpts{
Config: config, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -317,9 +317,9 @@ func TestContextValidate_selfRefMulti(t *testing.T) {
func TestContextValidate_selfRefMultiAll(t *testing.T) { func TestContextValidate_selfRefMultiAll(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
config := testConfig(t, "validate-self-ref-multi-all") m := testModule(t, "validate-self-ref-multi-all")
c := testContext(t, &ContextOpts{ c := testContext(t, &ContextOpts{
Config: config, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -335,12 +335,12 @@ func TestContextValidate_selfRefMultiAll(t *testing.T) {
} }
func TestContextApply(t *testing.T) { func TestContextApply(t *testing.T) {
c := testConfig(t, "apply-good") m := testModule(t, "apply-good")
p := testProvider("aws") p := testProvider("aws")
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -368,12 +368,12 @@ func TestContextApply(t *testing.T) {
} }
func TestContextApply_Minimal(t *testing.T) { func TestContextApply_Minimal(t *testing.T) {
c := testConfig(t, "apply-minimal") m := testModule(t, "apply-minimal")
p := testProvider("aws") p := testProvider("aws")
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -396,12 +396,12 @@ func TestContextApply_Minimal(t *testing.T) {
} }
func TestContextApply_badDiff(t *testing.T) { func TestContextApply_badDiff(t *testing.T) {
c := testConfig(t, "apply-good") m := testModule(t, "apply-good")
p := testProvider("aws") p := testProvider("aws")
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -427,10 +427,10 @@ func TestContextApply_badDiff(t *testing.T) {
func TestContextApply_cancel(t *testing.T) { func TestContextApply_cancel(t *testing.T) {
stopped := false stopped := false
c := testConfig(t, "apply-cancel") m := testModule(t, "apply-cancel")
p := testProvider("aws") p := testProvider("aws")
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -495,12 +495,12 @@ func TestContextApply_cancel(t *testing.T) {
} }
func TestContextApply_compute(t *testing.T) { func TestContextApply_compute(t *testing.T) {
c := testConfig(t, "apply-compute") m := testModule(t, "apply-compute")
p := testProvider("aws") p := testProvider("aws")
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -525,12 +525,12 @@ func TestContextApply_compute(t *testing.T) {
} }
func TestContextApply_nilDiff(t *testing.T) { func TestContextApply_nilDiff(t *testing.T) {
c := testConfig(t, "apply-good") m := testModule(t, "apply-good")
p := testProvider("aws") p := testProvider("aws")
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -550,7 +550,7 @@ func TestContextApply_nilDiff(t *testing.T) {
} }
func TestContextApply_Provisioner_compute(t *testing.T) { func TestContextApply_Provisioner_compute(t *testing.T) {
c := testConfig(t, "apply-provisioner-compute") m := testModule(t, "apply-provisioner-compute")
p := testProvider("aws") p := testProvider("aws")
pr := testProvisioner() pr := testProvisioner()
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
@ -564,7 +564,7 @@ func TestContextApply_Provisioner_compute(t *testing.T) {
return nil return nil
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -598,7 +598,7 @@ func TestContextApply_Provisioner_compute(t *testing.T) {
} }
func TestContextApply_provisionerFail(t *testing.T) { func TestContextApply_provisionerFail(t *testing.T) {
c := testConfig(t, "apply-provisioner-fail") m := testModule(t, "apply-provisioner-fail")
p := testProvider("aws") p := testProvider("aws")
pr := testProvisioner() pr := testProvisioner()
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
@ -609,7 +609,7 @@ func TestContextApply_provisionerFail(t *testing.T) {
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -638,7 +638,7 @@ func TestContextApply_provisionerFail(t *testing.T) {
} }
func TestContextApply_provisionerResourceRef(t *testing.T) { func TestContextApply_provisionerResourceRef(t *testing.T) {
c := testConfig(t, "apply-provisioner-resource-ref") m := testModule(t, "apply-provisioner-resource-ref")
p := testProvider("aws") p := testProvider("aws")
pr := testProvisioner() pr := testProvisioner()
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
@ -653,7 +653,7 @@ func TestContextApply_provisionerResourceRef(t *testing.T) {
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -684,7 +684,7 @@ func TestContextApply_provisionerResourceRef(t *testing.T) {
} }
func TestContextApply_outputDiffVars(t *testing.T) { func TestContextApply_outputDiffVars(t *testing.T) {
c := testConfig(t, "apply-good") m := testModule(t, "apply-good")
p := testProvider("aws") p := testProvider("aws")
s := &State{ s := &State{
Modules: []*ModuleState{ Modules: []*ModuleState{
@ -702,7 +702,7 @@ func TestContextApply_outputDiffVars(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -743,7 +743,7 @@ func TestContextApply_outputDiffVars(t *testing.T) {
} }
func TestContextApply_Provisioner_ConnInfo(t *testing.T) { func TestContextApply_Provisioner_ConnInfo(t *testing.T) {
c := testConfig(t, "apply-provisioner-conninfo") m := testModule(t, "apply-provisioner-conninfo")
p := testProvider("aws") p := testProvider("aws")
pr := testProvisioner() pr := testProvisioner()
@ -784,7 +784,7 @@ func TestContextApply_Provisioner_ConnInfo(t *testing.T) {
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -819,13 +819,13 @@ func TestContextApply_Provisioner_ConnInfo(t *testing.T) {
} }
func TestContextApply_destroy(t *testing.T) { func TestContextApply_destroy(t *testing.T) {
c := testConfig(t, "apply-destroy") m := testModule(t, "apply-destroy")
h := new(HookRecordApplyOrder) h := new(HookRecordApplyOrder)
p := testProvider("aws") p := testProvider("aws")
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Hooks: []Hook{h}, Hooks: []Hook{h},
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
@ -869,13 +869,13 @@ func TestContextApply_destroy(t *testing.T) {
} }
func TestContextApply_destroyOutputs(t *testing.T) { func TestContextApply_destroyOutputs(t *testing.T) {
c := testConfig(t, "apply-destroy-outputs") m := testModule(t, "apply-destroy-outputs")
h := new(HookRecordApplyOrder) h := new(HookRecordApplyOrder)
p := testProvider("aws") p := testProvider("aws")
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Hooks: []Hook{h}, Hooks: []Hook{h},
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
@ -910,7 +910,7 @@ func TestContextApply_destroyOutputs(t *testing.T) {
} }
func TestContextApply_destroyOrphan(t *testing.T) { func TestContextApply_destroyOrphan(t *testing.T) {
c := testConfig(t, "apply-error") m := testModule(t, "apply-error")
p := testProvider("aws") p := testProvider("aws")
s := &State{ s := &State{
Modules: []*ModuleState{ Modules: []*ModuleState{
@ -928,7 +928,7 @@ func TestContextApply_destroyOrphan(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -972,10 +972,10 @@ func TestContextApply_destroyOrphan(t *testing.T) {
func TestContextApply_error(t *testing.T) { func TestContextApply_error(t *testing.T) {
errored := false errored := false
c := testConfig(t, "apply-error") m := testModule(t, "apply-error")
p := testProvider("aws") p := testProvider("aws")
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1026,7 +1026,7 @@ func TestContextApply_error(t *testing.T) {
func TestContextApply_errorPartial(t *testing.T) { func TestContextApply_errorPartial(t *testing.T) {
errored := false errored := false
c := testConfig(t, "apply-error") m := testModule(t, "apply-error")
p := testProvider("aws") p := testProvider("aws")
s := &State{ s := &State{
Modules: []*ModuleState{ Modules: []*ModuleState{
@ -1044,7 +1044,7 @@ func TestContextApply_errorPartial(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1096,13 +1096,13 @@ func TestContextApply_errorPartial(t *testing.T) {
} }
func TestContextApply_hook(t *testing.T) { func TestContextApply_hook(t *testing.T) {
c := testConfig(t, "apply-good") m := testModule(t, "apply-good")
h := new(MockHook) h := new(MockHook)
p := testProvider("aws") p := testProvider("aws")
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Hooks: []Hook{h}, Hooks: []Hook{h},
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
@ -1126,10 +1126,10 @@ func TestContextApply_hook(t *testing.T) {
} }
func TestContextApply_idAttr(t *testing.T) { func TestContextApply_idAttr(t *testing.T) {
c := testConfig(t, "apply-idattr") m := testModule(t, "apply-idattr")
p := testProvider("aws") p := testProvider("aws")
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1177,12 +1177,12 @@ func TestContextApply_idAttr(t *testing.T) {
} }
func TestContextApply_output(t *testing.T) { func TestContextApply_output(t *testing.T) {
c := testConfig(t, "apply-output") m := testModule(t, "apply-output")
p := testProvider("aws") p := testProvider("aws")
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1205,12 +1205,12 @@ func TestContextApply_output(t *testing.T) {
} }
func TestContextApply_outputMulti(t *testing.T) { func TestContextApply_outputMulti(t *testing.T) {
c := testConfig(t, "apply-output-multi") m := testModule(t, "apply-output-multi")
p := testProvider("aws") p := testProvider("aws")
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1233,12 +1233,12 @@ func TestContextApply_outputMulti(t *testing.T) {
} }
func TestContextApply_outputMultiIndex(t *testing.T) { func TestContextApply_outputMultiIndex(t *testing.T) {
c := testConfig(t, "apply-output-multi-index") m := testModule(t, "apply-output-multi-index")
p := testProvider("aws") p := testProvider("aws")
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1261,7 +1261,7 @@ func TestContextApply_outputMultiIndex(t *testing.T) {
} }
func TestContextApply_taint(t *testing.T) { func TestContextApply_taint(t *testing.T) {
c := testConfig(t, "apply-taint") m := testModule(t, "apply-taint")
p := testProvider("aws") p := testProvider("aws")
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
@ -1287,7 +1287,7 @@ func TestContextApply_taint(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1311,12 +1311,12 @@ func TestContextApply_taint(t *testing.T) {
} }
func TestContextApply_unknownAttribute(t *testing.T) { func TestContextApply_unknownAttribute(t *testing.T) {
c := testConfig(t, "apply-unknown") m := testModule(t, "apply-unknown")
p := testProvider("aws") p := testProvider("aws")
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1339,12 +1339,12 @@ func TestContextApply_unknownAttribute(t *testing.T) {
} }
func TestContextApply_vars(t *testing.T) { func TestContextApply_vars(t *testing.T) {
c := testConfig(t, "apply-vars") m := testModule(t, "apply-vars")
p := testProvider("aws") p := testProvider("aws")
p.ApplyFn = testApplyFn p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1379,11 +1379,11 @@ func TestContextApply_vars(t *testing.T) {
} }
func TestContextPlan(t *testing.T) { func TestContextPlan(t *testing.T) {
c := testConfig(t, "plan-good") m := testModule(t, "plan-good")
p := testProvider("aws") p := testProvider("aws")
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1406,11 +1406,11 @@ func TestContextPlan(t *testing.T) {
} }
func TestContextPlan_minimal(t *testing.T) { func TestContextPlan_minimal(t *testing.T) {
c := testConfig(t, "plan-empty") m := testModule(t, "plan-empty")
p := testProvider("aws") p := testProvider("aws")
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1429,11 +1429,11 @@ func TestContextPlan_minimal(t *testing.T) {
} }
func TestContextPlan_nil(t *testing.T) { func TestContextPlan_nil(t *testing.T) {
c := testConfig(t, "plan-nil") m := testModule(t, "plan-nil")
p := testProvider("aws") p := testProvider("aws")
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1464,11 +1464,11 @@ func TestContextPlan_nil(t *testing.T) {
} }
func TestContextPlan_computed(t *testing.T) { func TestContextPlan_computed(t *testing.T) {
c := testConfig(t, "plan-computed") m := testModule(t, "plan-computed")
p := testProvider("aws") p := testProvider("aws")
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1487,11 +1487,11 @@ func TestContextPlan_computed(t *testing.T) {
} }
func TestContextPlan_computedList(t *testing.T) { func TestContextPlan_computedList(t *testing.T) {
c := testConfig(t, "plan-computed-list") m := testModule(t, "plan-computed-list")
p := testProvider("aws") p := testProvider("aws")
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1510,11 +1510,11 @@ func TestContextPlan_computedList(t *testing.T) {
} }
func TestContextPlan_count(t *testing.T) { func TestContextPlan_count(t *testing.T) {
c := testConfig(t, "plan-count") m := testModule(t, "plan-count")
p := testProvider("aws") p := testProvider("aws")
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1537,7 +1537,7 @@ func TestContextPlan_count(t *testing.T) {
} }
func TestContextPlan_countDecreaseToOne(t *testing.T) { func TestContextPlan_countDecreaseToOne(t *testing.T) {
c := testConfig(t, "plan-count-dec") m := testModule(t, "plan-count-dec")
p := testProvider("aws") p := testProvider("aws")
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
s := &State{ s := &State{
@ -1572,7 +1572,7 @@ func TestContextPlan_countDecreaseToOne(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1592,7 +1592,7 @@ func TestContextPlan_countDecreaseToOne(t *testing.T) {
} }
func TestContextPlan_countIncreaseFromNotSet(t *testing.T) { func TestContextPlan_countIncreaseFromNotSet(t *testing.T) {
c := testConfig(t, "plan-count-inc") m := testModule(t, "plan-count-inc")
p := testProvider("aws") p := testProvider("aws")
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
s := &State{ s := &State{
@ -1615,7 +1615,7 @@ func TestContextPlan_countIncreaseFromNotSet(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1635,7 +1635,7 @@ func TestContextPlan_countIncreaseFromNotSet(t *testing.T) {
} }
func TestContextPlan_countIncreaseFromOne(t *testing.T) { func TestContextPlan_countIncreaseFromOne(t *testing.T) {
c := testConfig(t, "plan-count-inc") m := testModule(t, "plan-count-inc")
p := testProvider("aws") p := testProvider("aws")
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
s := &State{ s := &State{
@ -1658,7 +1658,7 @@ func TestContextPlan_countIncreaseFromOne(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1678,7 +1678,7 @@ func TestContextPlan_countIncreaseFromOne(t *testing.T) {
} }
func TestContextPlan_destroy(t *testing.T) { func TestContextPlan_destroy(t *testing.T) {
c := testConfig(t, "plan-destroy") m := testModule(t, "plan-destroy")
p := testProvider("aws") p := testProvider("aws")
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
s := &State{ s := &State{
@ -1703,7 +1703,7 @@ func TestContextPlan_destroy(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1727,7 +1727,7 @@ func TestContextPlan_destroy(t *testing.T) {
} }
func TestContextPlan_diffVar(t *testing.T) { func TestContextPlan_diffVar(t *testing.T) {
c := testConfig(t, "plan-diffvar") m := testModule(t, "plan-diffvar")
p := testProvider("aws") p := testProvider("aws")
s := &State{ s := &State{
Modules: []*ModuleState{ Modules: []*ModuleState{
@ -1747,7 +1747,7 @@ func TestContextPlan_diffVar(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1785,12 +1785,12 @@ func TestContextPlan_diffVar(t *testing.T) {
} }
func TestContextPlan_hook(t *testing.T) { func TestContextPlan_hook(t *testing.T) {
c := testConfig(t, "plan-good") m := testModule(t, "plan-good")
h := new(MockHook) h := new(MockHook)
p := testProvider("aws") p := testProvider("aws")
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Hooks: []Hook{h}, Hooks: []Hook{h},
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
@ -1811,7 +1811,7 @@ func TestContextPlan_hook(t *testing.T) {
} }
func TestContextPlan_orphan(t *testing.T) { func TestContextPlan_orphan(t *testing.T) {
c := testConfig(t, "plan-orphan") m := testModule(t, "plan-orphan")
p := testProvider("aws") p := testProvider("aws")
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
s := &State{ s := &State{
@ -1830,7 +1830,7 @@ func TestContextPlan_orphan(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1850,7 +1850,7 @@ func TestContextPlan_orphan(t *testing.T) {
} }
func TestContextPlan_state(t *testing.T) { func TestContextPlan_state(t *testing.T) {
c := testConfig(t, "plan-good") m := testModule(t, "plan-good")
p := testProvider("aws") p := testProvider("aws")
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
s := &State{ s := &State{
@ -1868,7 +1868,7 @@ func TestContextPlan_state(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1892,7 +1892,7 @@ func TestContextPlan_state(t *testing.T) {
} }
func TestContextPlan_taint(t *testing.T) { func TestContextPlan_taint(t *testing.T) {
c := testConfig(t, "plan-taint") m := testModule(t, "plan-taint")
p := testProvider("aws") p := testProvider("aws")
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
s := &State{ s := &State{
@ -1920,7 +1920,7 @@ func TestContextPlan_taint(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1940,7 +1940,7 @@ func TestContextPlan_taint(t *testing.T) {
} }
func TestContextPlan_multiple_taint(t *testing.T) { func TestContextPlan_multiple_taint(t *testing.T) {
c := testConfig(t, "plan-taint") m := testModule(t, "plan-taint")
p := testProvider("aws") p := testProvider("aws")
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
s := &State{ s := &State{
@ -1971,7 +1971,7 @@ func TestContextPlan_multiple_taint(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -1991,11 +1991,11 @@ func TestContextPlan_multiple_taint(t *testing.T) {
} }
func TestContextPlan_varMultiCountOne(t *testing.T) { func TestContextPlan_varMultiCountOne(t *testing.T) {
c := testConfig(t, "plan-var-multi-count-one") m := testModule(t, "plan-var-multi-count-one")
p := testProvider("aws") p := testProvider("aws")
p.DiffFn = testDiffFn p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -2015,9 +2015,9 @@ func TestContextPlan_varMultiCountOne(t *testing.T) {
func TestContextRefresh(t *testing.T) { func TestContextRefresh(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
c := testConfig(t, "refresh-basic") m := testModule(t, "refresh-basic")
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -2067,9 +2067,9 @@ func TestContextRefresh(t *testing.T) {
func TestContextRefresh_delete(t *testing.T) { func TestContextRefresh_delete(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
c := testConfig(t, "refresh-basic") m := testModule(t, "refresh-basic")
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -2106,9 +2106,9 @@ func TestContextRefresh_delete(t *testing.T) {
func TestContextRefresh_ignoreUncreated(t *testing.T) { func TestContextRefresh_ignoreUncreated(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
c := testConfig(t, "refresh-basic") m := testModule(t, "refresh-basic")
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -2132,9 +2132,9 @@ func TestContextRefresh_ignoreUncreated(t *testing.T) {
func TestContextRefresh_hook(t *testing.T) { func TestContextRefresh_hook(t *testing.T) {
h := new(MockHook) h := new(MockHook)
p := testProvider("aws") p := testProvider("aws")
c := testConfig(t, "refresh-basic") m := testModule(t, "refresh-basic")
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Hooks: []Hook{h}, Hooks: []Hook{h},
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
@ -2181,7 +2181,7 @@ func TestContextRefresh_hook(t *testing.T) {
func TestContextRefresh_state(t *testing.T) { func TestContextRefresh_state(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
c := testConfig(t, "refresh-basic") m := testModule(t, "refresh-basic")
state := &State{ state := &State{
Modules: []*ModuleState{ Modules: []*ModuleState{
&ModuleState{ &ModuleState{
@ -2197,7 +2197,7 @@ func TestContextRefresh_state(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -2228,7 +2228,7 @@ func TestContextRefresh_state(t *testing.T) {
func TestContextRefresh_tainted(t *testing.T) { func TestContextRefresh_tainted(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
c := testConfig(t, "refresh-basic") m := testModule(t, "refresh-basic")
state := &State{ state := &State{
Modules: []*ModuleState{ Modules: []*ModuleState{
&ModuleState{ &ModuleState{
@ -2247,7 +2247,7 @@ func TestContextRefresh_tainted(t *testing.T) {
}, },
} }
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
@ -2276,9 +2276,9 @@ func TestContextRefresh_tainted(t *testing.T) {
func TestContextRefresh_vars(t *testing.T) { func TestContextRefresh_vars(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
c := testConfig(t, "refresh-vars") m := testModule(t, "refresh-vars")
ctx := testContext(t, &ContextOpts{ ctx := testContext(t, &ContextOpts{
Config: c, Module: m,
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },

View File

@ -8,6 +8,7 @@ import (
"strings" "strings"
"github.com/hashicorp/terraform/config" "github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/config/module"
"github.com/hashicorp/terraform/depgraph" "github.com/hashicorp/terraform/depgraph"
"github.com/hashicorp/terraform/helper/multierror" "github.com/hashicorp/terraform/helper/multierror"
) )
@ -20,7 +21,11 @@ import (
type GraphOpts struct { type GraphOpts struct {
// Config is the configuration from which to build the basic graph. // Config is the configuration from which to build the basic graph.
// This is the only required item. // This is the only required item.
Config *config.Config //Config *config.Config
// Module is the relative root of a module tree for this graph. This
// is the only required item.
Module *module.Tree
// Diff of changes that will be applied to the given state. This will // Diff of changes that will be applied to the given state. This will
// associate a ResourceDiff with applicable resources. Additionally, // associate a ResourceDiff with applicable resources. Additionally,
@ -101,10 +106,12 @@ type GraphNodeResourceProvider struct {
// configured at this point. // configured at this point.
// //
func Graph(opts *GraphOpts) (*depgraph.Graph, error) { func Graph(opts *GraphOpts) (*depgraph.Graph, error) {
if opts.Config == nil { if opts.Module == nil {
return nil, errors.New("Config is required for Graph") return nil, errors.New("Module is required for Graph")
} }
config := opts.Module.Config()
log.Printf("[DEBUG] Creating graph...") log.Printf("[DEBUG] Creating graph...")
g := new(depgraph.Graph) g := new(depgraph.Graph)
@ -112,24 +119,24 @@ func Graph(opts *GraphOpts) (*depgraph.Graph, error) {
// First, build the initial resource graph. This only has the resources // First, build the initial resource graph. This only has the resources
// and no dependencies. This only adds resources that are in the config // and no dependencies. This only adds resources that are in the config
// and not "orphans" (that are in the state, but not in the config). // and not "orphans" (that are in the state, but not in the config).
graphAddConfigResources(g, opts.Config, opts.State) graphAddConfigResources(g, config, opts.State)
// Add the modules that are in the configuration. // Add the modules that are in the configuration.
graphAddConfigModules(g, opts) graphAddConfigModules(g, config, opts)
// Add explicit dependsOn dependencies to the graph // Add explicit dependsOn dependencies to the graph
graphAddExplicitDeps(g) graphAddExplicitDeps(g)
if opts.State != nil { if opts.State != nil {
// Next, add the state orphans if we have any // Next, add the state orphans if we have any
graphAddOrphans(g, opts.Config, opts.State) graphAddOrphans(g, config, opts.State)
// Add tainted resources if we have any. // Add tainted resources if we have any.
graphAddTainted(g, opts.State) graphAddTainted(g, opts.State)
} }
// Map the provider configurations to all of the resources // Map the provider configurations to all of the resources
graphAddProviderConfigs(g, opts.Config) graphAddProviderConfigs(g, config)
// Setup the provisioners. These may have variable dependencies, // Setup the provisioners. These may have variable dependencies,
// and must be done before dependency setup // and must be done before dependency setup
@ -231,9 +238,7 @@ func graphInitState(s *State, g *depgraph.Graph) {
// graphAddConfigModules adds the modules from a configuration structure // graphAddConfigModules adds the modules from a configuration structure
// into the graph, expanding each to their own sub-graph. // into the graph, expanding each to their own sub-graph.
func graphAddConfigModules(g *depgraph.Graph, opts *GraphOpts) { func graphAddConfigModules(g *depgraph.Graph, c *config.Config, opts *GraphOpts) {
c := opts.Config
// Just short-circuit the whole thing if we don't have modules // Just short-circuit the whole thing if we don't have modules
if len(c.Modules) == 0 { if len(c.Modules) == 0 {
return return

View File

@ -7,9 +7,9 @@ import (
) )
func TestGraph(t *testing.T) { func TestGraph(t *testing.T) {
config := testConfig(t, "graph-basic") m := testModule(t, "graph-basic")
g, err := Graph(&GraphOpts{Config: config}) g, err := Graph(&GraphOpts{Module: m})
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -28,9 +28,9 @@ func TestGraph_configRequired(t *testing.T) {
} }
func TestGraph_count(t *testing.T) { func TestGraph_count(t *testing.T) {
config := testConfig(t, "graph-count") m := testModule(t, "graph-count")
g, err := Graph(&GraphOpts{Config: config}) g, err := Graph(&GraphOpts{Module: m})
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -43,18 +43,18 @@ func TestGraph_count(t *testing.T) {
} }
func TestGraph_cycle(t *testing.T) { func TestGraph_cycle(t *testing.T) {
config := testConfig(t, "graph-cycle") m := testModule(t, "graph-cycle")
_, err := Graph(&GraphOpts{Config: config}) _, err := Graph(&GraphOpts{Module: m})
if err == nil { if err == nil {
t.Fatal("should error") t.Fatal("should error")
} }
} }
func TestGraph_dependsOn(t *testing.T) { func TestGraph_dependsOn(t *testing.T) {
config := testConfig(t, "graph-depends-on") m := testModule(t, "graph-depends-on")
g, err := Graph(&GraphOpts{Config: config}) g, err := Graph(&GraphOpts{Module: m})
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -67,9 +67,9 @@ func TestGraph_dependsOn(t *testing.T) {
} }
func TestGraph_dependsOnCount(t *testing.T) { func TestGraph_dependsOnCount(t *testing.T) {
config := testConfig(t, "graph-depends-on-count") m := testModule(t, "graph-depends-on-count")
g, err := Graph(&GraphOpts{Config: config}) g, err := Graph(&GraphOpts{Module: m})
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -82,9 +82,9 @@ func TestGraph_dependsOnCount(t *testing.T) {
} }
func TestGraph_modules(t *testing.T) { func TestGraph_modules(t *testing.T) {
config := testConfig(t, "graph-modules") m := testModule(t, "graph-modules")
g, err := Graph(&GraphOpts{Config: config}) g, err := Graph(&GraphOpts{Module: m})
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -97,7 +97,7 @@ func TestGraph_modules(t *testing.T) {
} }
func TestGraph_state(t *testing.T) { func TestGraph_state(t *testing.T) {
config := testConfig(t, "graph-basic") m := testModule(t, "graph-basic")
state := &State{ state := &State{
Modules: []*ModuleState{ Modules: []*ModuleState{
&ModuleState{ &ModuleState{
@ -115,7 +115,7 @@ func TestGraph_state(t *testing.T) {
}, },
} }
g, err := Graph(&GraphOpts{Config: config, State: state}) g, err := Graph(&GraphOpts{Module: m, State: state})
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -128,7 +128,7 @@ func TestGraph_state(t *testing.T) {
} }
func TestGraph_tainted(t *testing.T) { func TestGraph_tainted(t *testing.T) {
config := testConfig(t, "graph-tainted") m := testModule(t, "graph-tainted")
state := &State{ state := &State{
Modules: []*ModuleState{ Modules: []*ModuleState{
&ModuleState{ &ModuleState{
@ -151,7 +151,7 @@ func TestGraph_tainted(t *testing.T) {
}, },
} }
g, err := Graph(&GraphOpts{Config: config, State: state}) g, err := Graph(&GraphOpts{Module: m, State: state})
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -164,7 +164,7 @@ func TestGraph_tainted(t *testing.T) {
} }
func TestGraph_taintedMulti(t *testing.T) { func TestGraph_taintedMulti(t *testing.T) {
config := testConfig(t, "graph-tainted") m := testModule(t, "graph-tainted")
state := &State{ state := &State{
Modules: []*ModuleState{ Modules: []*ModuleState{
&ModuleState{ &ModuleState{
@ -190,7 +190,7 @@ func TestGraph_taintedMulti(t *testing.T) {
}, },
} }
g, err := Graph(&GraphOpts{Config: config, State: state}) g, err := Graph(&GraphOpts{Module: m, State: state})
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -220,8 +220,8 @@ func TestGraphFull(t *testing.T) {
"open": testProviderFuncFixed(rpOS), "open": testProviderFuncFixed(rpOS),
} }
c := testConfig(t, "graph-basic") m := testModule(t, "graph-basic")
g, err := Graph(&GraphOpts{Config: c, Providers: ps}) g, err := Graph(&GraphOpts{Module: m, Providers: ps})
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -276,8 +276,8 @@ func TestGraphProvisioners(t *testing.T) {
"aws": testProviderFuncFixed(rpAws), "aws": testProviderFuncFixed(rpAws),
} }
c := testConfig(t, "graph-provisioners") m := testModule(t, "graph-provisioners")
g, err := Graph(&GraphOpts{Config: c, Providers: pf, Provisioners: ps}) g, err := Graph(&GraphOpts{Module: m, Providers: pf, Provisioners: ps})
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -339,7 +339,7 @@ func TestGraphProvisioners(t *testing.T) {
} }
func TestGraphAddDiff(t *testing.T) { func TestGraphAddDiff(t *testing.T) {
config := testConfig(t, "graph-diff") m := testModule(t, "graph-diff")
diff := &Diff{ diff := &Diff{
Resources: map[string]*InstanceDiff{ Resources: map[string]*InstanceDiff{
"aws_instance.foo": &InstanceDiff{ "aws_instance.foo": &InstanceDiff{
@ -352,7 +352,7 @@ func TestGraphAddDiff(t *testing.T) {
}, },
} }
g, err := Graph(&GraphOpts{Config: config, Diff: diff}) g, err := Graph(&GraphOpts{Module: m, Diff: diff})
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -375,7 +375,7 @@ func TestGraphAddDiff(t *testing.T) {
} }
func TestGraphAddDiff_destroy(t *testing.T) { func TestGraphAddDiff_destroy(t *testing.T) {
config := testConfig(t, "graph-diff-destroy") m := testModule(t, "graph-diff-destroy")
diff := &Diff{ diff := &Diff{
Resources: map[string]*InstanceDiff{ Resources: map[string]*InstanceDiff{
"aws_instance.foo": &InstanceDiff{ "aws_instance.foo": &InstanceDiff{
@ -413,7 +413,7 @@ func TestGraphAddDiff_destroy(t *testing.T) {
diffHash := checksumStruct(t, diff) diffHash := checksumStruct(t, diff)
g, err := Graph(&GraphOpts{ g, err := Graph(&GraphOpts{
Config: config, Module: m,
Diff: diff, Diff: diff,
State: state, State: state,
}) })
@ -445,7 +445,7 @@ func TestGraphAddDiff_destroy(t *testing.T) {
} }
func TestGraphAddDiff_destroy_counts(t *testing.T) { func TestGraphAddDiff_destroy_counts(t *testing.T) {
config := testConfig(t, "graph-count") m := testModule(t, "graph-count")
diff := &Diff{ diff := &Diff{
Resources: map[string]*InstanceDiff{ Resources: map[string]*InstanceDiff{
"aws_instance.web.0": &InstanceDiff{ "aws_instance.web.0": &InstanceDiff{
@ -500,7 +500,7 @@ func TestGraphAddDiff_destroy_counts(t *testing.T) {
diffHash := checksumStruct(t, diff) diffHash := checksumStruct(t, diff)
g, err := Graph(&GraphOpts{ g, err := Graph(&GraphOpts{
Config: config, Module: m,
Diff: diff, Diff: diff,
State: state, State: state,
}) })
@ -532,7 +532,7 @@ func TestGraphAddDiff_destroy_counts(t *testing.T) {
} }
func TestGraphInitState(t *testing.T) { func TestGraphInitState(t *testing.T) {
config := testConfig(t, "graph-basic") m := testModule(t, "graph-basic")
state := &State{ state := &State{
Modules: []*ModuleState{ Modules: []*ModuleState{
&ModuleState{ &ModuleState{
@ -555,7 +555,7 @@ func TestGraphInitState(t *testing.T) {
}, },
} }
g, err := Graph(&GraphOpts{Config: config, State: state}) g, err := Graph(&GraphOpts{Module: m, State: state})
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -576,7 +576,7 @@ func TestGraphInitState(t *testing.T) {
} }
func TestGraphInitState_Count(t *testing.T) { func TestGraphInitState_Count(t *testing.T) {
config := testConfig(t, "graph-count") m := testModule(t, "graph-count")
state := &State{ state := &State{
Modules: []*ModuleState{ Modules: []*ModuleState{
&ModuleState{ &ModuleState{
@ -599,7 +599,7 @@ func TestGraphInitState_Count(t *testing.T) {
}, },
} }
g, err := Graph(&GraphOpts{Config: config, State: state}) g, err := Graph(&GraphOpts{Module: m, State: state})
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -620,7 +620,7 @@ func TestGraphInitState_Count(t *testing.T) {
} }
func TestGraph_orphan_dependencies(t *testing.T) { func TestGraph_orphan_dependencies(t *testing.T) {
config := testConfig(t, "graph-count") m := testModule(t, "graph-count")
state := &State{ state := &State{
Modules: []*ModuleState{ Modules: []*ModuleState{
&ModuleState{ &ModuleState{
@ -655,7 +655,7 @@ func TestGraph_orphan_dependencies(t *testing.T) {
}, },
} }
g, err := Graph(&GraphOpts{Config: config, State: state}) g, err := Graph(&GraphOpts{Module: m, State: state})
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }

View File

@ -9,6 +9,7 @@ import (
"sync" "sync"
"github.com/hashicorp/terraform/config" "github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/config/module"
) )
func init() { func init() {
@ -43,8 +44,8 @@ type Plan struct {
// The following fields in opts are overridden by the plan: Config, // The following fields in opts are overridden by the plan: Config,
// Diff, State, Variables. // Diff, State, Variables.
func (p *Plan) Context(opts *ContextOpts) *Context { func (p *Plan) Context(opts *ContextOpts) *Context {
opts.Config = p.Config
opts.Diff = p.Diff opts.Diff = p.Diff
opts.Module = module.NewTree("", p.Config) // TODO: compat
opts.State = p.State opts.State = p.State
opts.Variables = p.Vars opts.Variables = p.Vars
return NewContext(opts) return NewContext(opts)

View File

@ -10,6 +10,7 @@ import (
"testing" "testing"
"github.com/hashicorp/terraform/config" "github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/config/module"
) )
// This is the directory where our test fixtures are. // This is the directory where our test fixtures are.
@ -39,6 +40,15 @@ func testConfig(t *testing.T, name string) *config.Config {
return c return c
} }
func testModule(t *testing.T, name string) *module.Tree {
mod, err := module.NewTreeModule("", filepath.Join(fixtureDir, name))
if err != nil {
t.Fatalf("err: %s", err)
}
return mod
}
func testProviderFuncFixed(rp ResourceProvider) ResourceProviderFactory { func testProviderFuncFixed(rp ResourceProvider) ResourceProviderFactory {
return func() (ResourceProvider, error) { return func() (ResourceProvider, error) {
return rp, nil return rp, nil