cleanup
This commit is contained in:
parent
db7596c045
commit
1536c531ff
|
@ -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) {
|
func TestContext2Plan_moduleProviderDefaultsVar(t *testing.T) {
|
||||||
var l sync.Mutex
|
var l sync.Mutex
|
||||||
var calls []string
|
var calls []string
|
||||||
|
|
|
@ -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
|
//// FIXME: provider must still exist in config, but we should be able to locate
|
||||||
//// it elsewhere
|
//// it elsewhere
|
||||||
//func TestContext2Validate_moduleProviderInheritOrphan(t *testing.T) {
|
//func TestContext2Validate_moduleProviderInheritOrphan(t *testing.T) {
|
||||||
|
|
|
@ -40,8 +40,6 @@ type EvalContext interface {
|
||||||
// is used to store the provider configuration for inheritance lookups
|
// is used to store the provider configuration for inheritance lookups
|
||||||
// with ParentProviderConfig().
|
// with ParentProviderConfig().
|
||||||
ConfigureProvider(string, *ResourceConfig) error
|
ConfigureProvider(string, *ResourceConfig) error
|
||||||
//SetProviderConfig(string, *ResourceConfig) error
|
|
||||||
//ParentProviderConfig(string) *ResourceConfig
|
|
||||||
|
|
||||||
// ProviderInput and SetProviderInput are used to configure providers
|
// ProviderInput and SetProviderInput are used to configure providers
|
||||||
// from user input.
|
// from user input.
|
||||||
|
|
|
@ -30,11 +30,10 @@ type BuiltinEvalContext struct {
|
||||||
InterpolaterVars map[string]map[string]interface{}
|
InterpolaterVars map[string]map[string]interface{}
|
||||||
InterpolaterVarLock *sync.Mutex
|
InterpolaterVarLock *sync.Mutex
|
||||||
|
|
||||||
Components contextComponentFactory
|
Components contextComponentFactory
|
||||||
Hooks []Hook
|
Hooks []Hook
|
||||||
InputValue UIInput
|
InputValue UIInput
|
||||||
ProviderCache map[string]ResourceProvider
|
ProviderCache map[string]ResourceProvider
|
||||||
//ProviderConfigCache map[string]*ResourceConfig
|
|
||||||
ProviderInputConfig map[string]map[string]interface{}
|
ProviderInputConfig map[string]map[string]interface{}
|
||||||
ProviderLock *sync.Mutex
|
ProviderLock *sync.Mutex
|
||||||
ProvisionerCache map[string]ResourceProvisioner
|
ProvisionerCache map[string]ResourceProvisioner
|
||||||
|
@ -149,29 +148,9 @@ func (ctx *BuiltinEvalContext) ConfigureProvider(
|
||||||
if p == nil {
|
if p == nil {
|
||||||
return fmt.Errorf("Provider '%s' not initialized", n)
|
return fmt.Errorf("Provider '%s' not initialized", n)
|
||||||
}
|
}
|
||||||
|
|
||||||
//if err := ctx.SetProviderConfig(n, cfg); err != nil {
|
|
||||||
// return nil
|
|
||||||
//}
|
|
||||||
|
|
||||||
return p.Configure(cfg)
|
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{} {
|
func (ctx *BuiltinEvalContext) ProviderInput(n string) map[string]interface{} {
|
||||||
ctx.ProviderLock.Lock()
|
ctx.ProviderLock.Lock()
|
||||||
defer ctx.ProviderLock.Unlock()
|
defer ctx.ProviderLock.Unlock()
|
||||||
|
@ -204,28 +183,6 @@ func (ctx *BuiltinEvalContext) SetProviderInput(n string, c map[string]interface
|
||||||
ctx.ProviderLock.Unlock()
|
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(
|
func (ctx *BuiltinEvalContext) InitProvisioner(
|
||||||
n string) (ResourceProvisioner, error) {
|
n string) (ResourceProvisioner, error) {
|
||||||
ctx.once.Do(ctx.init)
|
ctx.once.Do(ctx.init)
|
||||||
|
|
|
@ -45,14 +45,6 @@ type MockEvalContext struct {
|
||||||
ConfigureProviderConfig *ResourceConfig
|
ConfigureProviderConfig *ResourceConfig
|
||||||
ConfigureProviderError error
|
ConfigureProviderError error
|
||||||
|
|
||||||
//SetProviderConfigCalled bool
|
|
||||||
//SetProviderConfigName string
|
|
||||||
//SetProviderConfigConfig *ResourceConfig
|
|
||||||
|
|
||||||
//ParentProviderConfigCalled bool
|
|
||||||
//ParentProviderConfigName string
|
|
||||||
//ParentProviderConfigConfig *ResourceConfig
|
|
||||||
|
|
||||||
InitProvisionerCalled bool
|
InitProvisionerCalled bool
|
||||||
InitProvisionerName string
|
InitProvisionerName string
|
||||||
InitProvisionerProvisioner ResourceProvisioner
|
InitProvisionerProvisioner ResourceProvisioner
|
||||||
|
@ -140,20 +132,6 @@ func (c *MockEvalContext) ConfigureProvider(n string, cfg *ResourceConfig) error
|
||||||
return c.ConfigureProviderError
|
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{} {
|
func (c *MockEvalContext) ProviderInput(n string) map[string]interface{} {
|
||||||
c.ProviderInputCalled = true
|
c.ProviderInputCalled = true
|
||||||
c.ProviderInputName = n
|
c.ProviderInputName = n
|
||||||
|
|
|
@ -6,18 +6,6 @@ import (
|
||||||
"github.com/hashicorp/terraform/config"
|
"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
|
// EvalBuildProviderConfig outputs a *ResourceConfig that is properly
|
||||||
// merged with parents and inputs on top of what is configured in the file.
|
// merged with parents and inputs on top of what is configured in the file.
|
||||||
type EvalBuildProviderConfig struct {
|
type EvalBuildProviderConfig struct {
|
||||||
|
@ -45,12 +33,6 @@ func (n *EvalBuildProviderConfig) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
cfg = NewResourceConfig(merged)
|
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
|
*n.Output = cfg
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,10 +26,6 @@ func TestEvalBuildProviderConfig(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := &MockEvalContext{
|
ctx := &MockEvalContext{
|
||||||
//ParentProviderConfigConfig: testResourceConfig(t, map[string]interface{}{
|
|
||||||
// "inherited_from_parent": "parent",
|
|
||||||
// "set_in_config_and_parent": "parent",
|
|
||||||
//}),
|
|
||||||
ProviderInputConfig: map[string]interface{}{
|
ProviderInputConfig: map[string]interface{}{
|
||||||
"set_in_config": "input",
|
"set_in_config": "input",
|
||||||
"set_by_input": "input",
|
"set_by_input": "input",
|
||||||
|
@ -43,47 +39,14 @@ func TestEvalBuildProviderConfig(t *testing.T) {
|
||||||
expected := map[string]interface{}{
|
expected := map[string]interface{}{
|
||||||
"set_in_config": "input", // in practice, input map contains identical literals from config
|
"set_in_config": "input", // in practice, input map contains identical literals from config
|
||||||
"set_in_config_and_parent": "config",
|
"set_in_config_and_parent": "config",
|
||||||
// no longer merging
|
"computed_in_config": "config",
|
||||||
//"inherited_from_parent": "parent",
|
"set_by_input": "input",
|
||||||
"computed_in_config": "config",
|
|
||||||
"set_by_input": "input",
|
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(config.Raw, expected) {
|
if !reflect.DeepEqual(config.Raw, expected) {
|
||||||
t.Fatalf("incorrect merged config:\n%#v\nwanted:\n%#v", 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) {
|
func TestEvalConfigProvider_impl(t *testing.T) {
|
||||||
var _ EvalNode = new(EvalConfigProvider)
|
var _ EvalNode = new(EvalConfigProvider)
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,10 +61,6 @@ func ProviderEvalTree(n string, config *config.ProviderConfig) EvalNode {
|
||||||
Provider: &provider,
|
Provider: &provider,
|
||||||
Config: &resourceConfig,
|
Config: &resourceConfig,
|
||||||
},
|
},
|
||||||
&EvalSetProviderConfig{
|
|
||||||
Provider: n,
|
|
||||||
Config: &resourceConfig,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -87,10 +83,6 @@ func ProviderEvalTree(n string, config *config.ProviderConfig) EvalNode {
|
||||||
Config: &resourceConfig,
|
Config: &resourceConfig,
|
||||||
Output: &resourceConfig,
|
Output: &resourceConfig,
|
||||||
},
|
},
|
||||||
&EvalSetProviderConfig{
|
|
||||||
Provider: n,
|
|
||||||
Config: &resourceConfig,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -32,10 +32,9 @@ type ContextGraphWalker struct {
|
||||||
interpolaterVars map[string]map[string]interface{}
|
interpolaterVars map[string]map[string]interface{}
|
||||||
interpolaterVarLock sync.Mutex
|
interpolaterVarLock sync.Mutex
|
||||||
providerCache map[string]ResourceProvider
|
providerCache map[string]ResourceProvider
|
||||||
//providerConfigCache map[string]*ResourceConfig
|
providerLock sync.Mutex
|
||||||
providerLock sync.Mutex
|
provisionerCache map[string]ResourceProvisioner
|
||||||
provisionerCache map[string]ResourceProvisioner
|
provisionerLock sync.Mutex
|
||||||
provisionerLock sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *ContextGraphWalker) EnterPath(path []string) EvalContext {
|
func (w *ContextGraphWalker) EnterPath(path []string) EvalContext {
|
||||||
|
|
|
@ -29,10 +29,6 @@ func (n *NodeDisabledProvider) EvalTree() EvalNode {
|
||||||
Config: &resourceConfig,
|
Config: &resourceConfig,
|
||||||
Output: &resourceConfig,
|
Output: &resourceConfig,
|
||||||
},
|
},
|
||||||
&EvalSetProviderConfig{
|
|
||||||
Provider: n.ProviderName(),
|
|
||||||
Config: &resourceConfig,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue