This commit is contained in:
James Bardin 2017-10-13 10:34:03 -04:00
parent db7596c045
commit 1536c531ff
10 changed files with 9 additions and 232 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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.

View File

@ -34,7 +34,6 @@ type BuiltinEvalContext struct {
Hooks []Hook
InputValue UIInput
ProviderCache map[string]ResourceProvider
//ProviderConfigCache map[string]*ResourceConfig
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)

View File

@ -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

View File

@ -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
}

View File

@ -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,8 +39,6 @@ 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",
}
@ -53,37 +47,6 @@ func TestEvalBuildProviderConfig(t *testing.T) {
}
}
//// 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)
}

View File

@ -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,
},
},
},
})

View File

@ -32,7 +32,6 @@ 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

View File

@ -29,10 +29,6 @@ func (n *NodeDisabledProvider) EvalTree() EvalNode {
Config: &resourceConfig,
Output: &resourceConfig,
},
&EvalSetProviderConfig{
Provider: n.ProviderName(),
Config: &resourceConfig,
},
},
}
}