From 1536c531ffddea7bf78c7ebf78382ffb599a5a0f Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 13 Oct 2017 10:34:03 -0400 Subject: [PATCH] cleanup --- terraform/context_plan_test.go | 62 ----------------------------- terraform/context_validate_test.go | 26 ------------ terraform/eval_context.go | 2 - terraform/eval_context_builtin.go | 51 ++---------------------- terraform/eval_context_mock.go | 22 ---------- terraform/eval_provider.go | 18 --------- terraform/eval_provider_test.go | 41 +------------------ terraform/evaltree_provider.go | 8 ---- terraform/graph_walk_context.go | 7 ++-- terraform/node_provider_disabled.go | 4 -- 10 files changed, 9 insertions(+), 232 deletions(-) diff --git a/terraform/context_plan_test.go b/terraform/context_plan_test.go index f1edab840..1894bf0cc 100644 --- a/terraform/context_plan_test.go +++ b/terraform/context_plan_test.go @@ -643,68 +643,6 @@ func TestContext2Plan_moduleProviderInheritDeep(t *testing.T) { } } -//// REMOVING: we no longer override child provider config -//func TestContext2Plan_moduleProviderDefaults(t *testing.T) { -// var l sync.Mutex -// var calls []string -// toCount := 0 - -// m := testModule(t, "plan-module-provider-defaults") -// ctx := testContext2(t, &ContextOpts{ -// Module: m, -// ProviderResolver: ResourceProviderResolverFixed( -// map[string]ResourceProviderFactory{ -// "aws": func() (ResourceProvider, error) { -// l.Lock() -// defer l.Unlock() - -// p := testProvider("aws") -// p.ConfigureFn = func(c *ResourceConfig) error { -// if v, ok := c.Get("from"); !ok || v.(string) != "root" { -// return fmt.Errorf("bad") -// } -// if v, ok := c.Get("to"); ok && v.(string) == "child" { -// toCount++ -// } - -// return nil -// } -// p.DiffFn = func( -// info *InstanceInfo, -// state *InstanceState, -// c *ResourceConfig) (*InstanceDiff, error) { -// v, _ := c.Get("from") - -// l.Lock() -// defer l.Unlock() -// calls = append(calls, v.(string)) -// return testDiffFn(info, state, c) -// } -// return p, nil -// }, -// }, -// ), -// }) - -// _, err := ctx.Plan() -// if err != nil { -// t.Fatalf("err: %s", err) -// } - -// if toCount != 1 { -// t.Fatalf( -// "provider in child didn't set proper config\n\n"+ -// "toCount: %d", toCount) -// } - -// actual := calls -// sort.Strings(actual) -// expected := []string{"child", "root"} -// if !reflect.DeepEqual(actual, expected) { -// t.Fatalf("bad: %#v", actual) -// } -//} - func TestContext2Plan_moduleProviderDefaultsVar(t *testing.T) { var l sync.Mutex var calls []string diff --git a/terraform/context_validate_test.go b/terraform/context_validate_test.go index d02df58b9..f2fb0895d 100644 --- a/terraform/context_validate_test.go +++ b/terraform/context_validate_test.go @@ -321,32 +321,6 @@ func TestContext2Validate_moduleDepsShouldNotCycle(t *testing.T) { } } -//// REMOVING: change in behavior, this should not be inherited -//func TestContext2Validate_moduleProviderInherit(t *testing.T) { -// m := testModule(t, "validate-module-pc-inherit") -// p := testProvider("aws") -// c := testContext2(t, &ContextOpts{ -// Module: m, -// ProviderResolver: ResourceProviderResolverFixed( -// map[string]ResourceProviderFactory{ -// "aws": testProviderFuncFixed(p), -// }, -// ), -// }) - -// p.ValidateFn = func(c *ResourceConfig) ([]string, []error) { -// return nil, c.CheckSet([]string{"set"}) -// } - -// w, e := c.Validate() -// if len(w) > 0 { -// t.Fatalf("bad: %#v", w) -// } -// if len(e) > 0 { -// t.Fatalf("bad: %s", e) -// } -//} - //// FIXME: provider must still exist in config, but we should be able to locate //// it elsewhere //func TestContext2Validate_moduleProviderInheritOrphan(t *testing.T) { diff --git a/terraform/eval_context.go b/terraform/eval_context.go index 83b764d74..655916fc3 100644 --- a/terraform/eval_context.go +++ b/terraform/eval_context.go @@ -40,8 +40,6 @@ type EvalContext interface { // is used to store the provider configuration for inheritance lookups // with ParentProviderConfig(). ConfigureProvider(string, *ResourceConfig) error - //SetProviderConfig(string, *ResourceConfig) error - //ParentProviderConfig(string) *ResourceConfig // ProviderInput and SetProviderInput are used to configure providers // from user input. diff --git a/terraform/eval_context_builtin.go b/terraform/eval_context_builtin.go index 5a0bb69e1..3b65ba7fa 100644 --- a/terraform/eval_context_builtin.go +++ b/terraform/eval_context_builtin.go @@ -30,11 +30,10 @@ type BuiltinEvalContext struct { InterpolaterVars map[string]map[string]interface{} InterpolaterVarLock *sync.Mutex - Components contextComponentFactory - Hooks []Hook - InputValue UIInput - ProviderCache map[string]ResourceProvider - //ProviderConfigCache map[string]*ResourceConfig + Components contextComponentFactory + Hooks []Hook + InputValue UIInput + ProviderCache map[string]ResourceProvider ProviderInputConfig map[string]map[string]interface{} ProviderLock *sync.Mutex ProvisionerCache map[string]ResourceProvisioner @@ -149,29 +148,9 @@ func (ctx *BuiltinEvalContext) ConfigureProvider( if p == nil { return fmt.Errorf("Provider '%s' not initialized", n) } - - //if err := ctx.SetProviderConfig(n, cfg); err != nil { - // return nil - //} - return p.Configure(cfg) } -// REMOVING: each provider will contain its own configuration -//func (ctx *BuiltinEvalContext) SetProviderConfig( -// n string, cfg *ResourceConfig) error { -// providerPath := make([]string, len(ctx.Path())+1) -// copy(providerPath, ctx.Path()) -// providerPath[len(providerPath)-1] = n - -// // Save the configuration -// ctx.ProviderLock.Lock() -// ctx.ProviderConfigCache[PathCacheKey(providerPath)] = cfg -// ctx.ProviderLock.Unlock() - -// return nil -//} - func (ctx *BuiltinEvalContext) ProviderInput(n string) map[string]interface{} { ctx.ProviderLock.Lock() defer ctx.ProviderLock.Unlock() @@ -204,28 +183,6 @@ func (ctx *BuiltinEvalContext) SetProviderInput(n string, c map[string]interface ctx.ProviderLock.Unlock() } -// REMOVING: Each provider will contain its own configuration -//func (ctx *BuiltinEvalContext) ParentProviderConfig(n string) *ResourceConfig { -// ctx.ProviderLock.Lock() -// defer ctx.ProviderLock.Unlock() - -// // Make a copy of the path so we can safely edit it -// path := ctx.Path() -// pathCopy := make([]string, len(path)+1) -// copy(pathCopy, path) - -// // Go up the tree. -// for i := len(path) - 1; i >= 0; i-- { -// pathCopy[i+1] = n -// k := PathCacheKey(pathCopy[:i+2]) -// if v, ok := ctx.ProviderConfigCache[k]; ok { -// return v -// } -// } - -// return nil -//} - func (ctx *BuiltinEvalContext) InitProvisioner( n string) (ResourceProvisioner, error) { ctx.once.Do(ctx.init) diff --git a/terraform/eval_context_mock.go b/terraform/eval_context_mock.go index bd903e4fc..a148a54bf 100644 --- a/terraform/eval_context_mock.go +++ b/terraform/eval_context_mock.go @@ -45,14 +45,6 @@ type MockEvalContext struct { ConfigureProviderConfig *ResourceConfig ConfigureProviderError error - //SetProviderConfigCalled bool - //SetProviderConfigName string - //SetProviderConfigConfig *ResourceConfig - - //ParentProviderConfigCalled bool - //ParentProviderConfigName string - //ParentProviderConfigConfig *ResourceConfig - InitProvisionerCalled bool InitProvisionerName string InitProvisionerProvisioner ResourceProvisioner @@ -140,20 +132,6 @@ func (c *MockEvalContext) ConfigureProvider(n string, cfg *ResourceConfig) error return c.ConfigureProviderError } -//func (c *MockEvalContext) SetProviderConfig( -// n string, cfg *ResourceConfig) error { -// c.SetProviderConfigCalled = true -// c.SetProviderConfigName = n -// c.SetProviderConfigConfig = cfg -// return nil -//} - -//func (c *MockEvalContext) ParentProviderConfig(n string) *ResourceConfig { -// c.ParentProviderConfigCalled = true -// c.ParentProviderConfigName = n -// return c.ParentProviderConfigConfig -//} - func (c *MockEvalContext) ProviderInput(n string) map[string]interface{} { c.ProviderInputCalled = true c.ProviderInputName = n diff --git a/terraform/eval_provider.go b/terraform/eval_provider.go index 8c0870a83..556588b59 100644 --- a/terraform/eval_provider.go +++ b/terraform/eval_provider.go @@ -6,18 +6,6 @@ import ( "github.com/hashicorp/terraform/config" ) -// EvalSetProviderConfig sets the parent configuration for a provider -// without configuring that provider, validating it, etc. -type EvalSetProviderConfig struct { - Provider string - Config **ResourceConfig -} - -func (n *EvalSetProviderConfig) Eval(ctx EvalContext) (interface{}, error) { - return nil, nil - //return nil, ctx.SetProviderConfig(n.Provider, *n.Config) -} - // EvalBuildProviderConfig outputs a *ResourceConfig that is properly // merged with parents and inputs on top of what is configured in the file. type EvalBuildProviderConfig struct { @@ -45,12 +33,6 @@ func (n *EvalBuildProviderConfig) Eval(ctx EvalContext) (interface{}, error) { cfg = NewResourceConfig(merged) } - //// Get the parent configuration if there is one - //if parent := ctx.ParentProviderConfig(n.Provider); parent != nil { - // merged := cfg.raw.Merge(parent.raw) - // cfg = NewResourceConfig(merged) - //} - *n.Output = cfg return nil, nil } diff --git a/terraform/eval_provider_test.go b/terraform/eval_provider_test.go index 01610c957..43653a7b7 100644 --- a/terraform/eval_provider_test.go +++ b/terraform/eval_provider_test.go @@ -26,10 +26,6 @@ func TestEvalBuildProviderConfig(t *testing.T) { } ctx := &MockEvalContext{ - //ParentProviderConfigConfig: testResourceConfig(t, map[string]interface{}{ - // "inherited_from_parent": "parent", - // "set_in_config_and_parent": "parent", - //}), ProviderInputConfig: map[string]interface{}{ "set_in_config": "input", "set_by_input": "input", @@ -43,47 +39,14 @@ func TestEvalBuildProviderConfig(t *testing.T) { expected := map[string]interface{}{ "set_in_config": "input", // in practice, input map contains identical literals from config "set_in_config_and_parent": "config", - // no longer merging - //"inherited_from_parent": "parent", - "computed_in_config": "config", - "set_by_input": "input", + "computed_in_config": "config", + "set_by_input": "input", } if !reflect.DeepEqual(config.Raw, expected) { t.Fatalf("incorrect merged config:\n%#v\nwanted:\n%#v", config.Raw, expected) } } -//// REMOVING: this is no longer expected behavior -//func TestEvalBuildProviderConfig_parentPriority(t *testing.T) { -// config := testResourceConfig(t, map[string]interface{}{}) -// provider := "foo" - -// n := &EvalBuildProviderConfig{ -// Provider: provider, -// Config: &config, -// Output: &config, -// } - -// ctx := &MockEvalContext{ -// //ParentProviderConfigConfig: testResourceConfig(t, map[string]interface{}{ -// // "foo": "bar", -// //}), -// ProviderInputConfig: map[string]interface{}{ -// "foo": "baz", -// }, -// } -// if _, err := n.Eval(ctx); err != nil { -// t.Fatalf("err: %s", err) -// } - -// expected := map[string]interface{}{ -// "foo": "bar", -// } -// if !reflect.DeepEqual(config.Raw, expected) { -// t.Fatalf("expected: %#v, got: %#v", expected, config.Raw) -// } -//} - func TestEvalConfigProvider_impl(t *testing.T) { var _ EvalNode = new(EvalConfigProvider) } diff --git a/terraform/evaltree_provider.go b/terraform/evaltree_provider.go index 378341ed1..55e5c5258 100644 --- a/terraform/evaltree_provider.go +++ b/terraform/evaltree_provider.go @@ -61,10 +61,6 @@ func ProviderEvalTree(n string, config *config.ProviderConfig) EvalNode { Provider: &provider, Config: &resourceConfig, }, - &EvalSetProviderConfig{ - Provider: n, - Config: &resourceConfig, - }, }, }, }) @@ -87,10 +83,6 @@ func ProviderEvalTree(n string, config *config.ProviderConfig) EvalNode { Config: &resourceConfig, Output: &resourceConfig, }, - &EvalSetProviderConfig{ - Provider: n, - Config: &resourceConfig, - }, }, }, }) diff --git a/terraform/graph_walk_context.go b/terraform/graph_walk_context.go index 6d49a6cf1..c2cca1499 100644 --- a/terraform/graph_walk_context.go +++ b/terraform/graph_walk_context.go @@ -32,10 +32,9 @@ type ContextGraphWalker struct { interpolaterVars map[string]map[string]interface{} interpolaterVarLock sync.Mutex providerCache map[string]ResourceProvider - //providerConfigCache map[string]*ResourceConfig - providerLock sync.Mutex - provisionerCache map[string]ResourceProvisioner - provisionerLock sync.Mutex + providerLock sync.Mutex + provisionerCache map[string]ResourceProvisioner + provisionerLock sync.Mutex } func (w *ContextGraphWalker) EnterPath(path []string) EvalContext { diff --git a/terraform/node_provider_disabled.go b/terraform/node_provider_disabled.go index e1d0b2483..a00bc46fb 100644 --- a/terraform/node_provider_disabled.go +++ b/terraform/node_provider_disabled.go @@ -29,10 +29,6 @@ func (n *NodeDisabledProvider) EvalTree() EvalNode { Config: &resourceConfig, Output: &resourceConfig, }, - &EvalSetProviderConfig{ - Provider: n.ProviderName(), - Config: &resourceConfig, - }, }, } }