reverse the merge order for cached provider Input

Previously when looking up cached provider input, the Input was taken in
its entirety, and only provider configuration fields that weren't in the
saved input were added. This would cause providers in modules to use the
entire configuration from parent modules, even if they themselves had
entirely different configs.

Note: this is only marginally beter than the old behavior. It may be
slightly more correct, but stil can't account for the user's intent, and
may be adding configured values from one provider into another.

Change the PathCacheKey to just join the path on a non-path character
(|), which makes for easier debugging.
This commit is contained in:
James Bardin 2017-10-16 13:42:55 -04:00
parent 1536c531ff
commit d8f4c1f618
3 changed files with 5 additions and 19 deletions

View File

@ -17,7 +17,7 @@ type EvalBuildProviderConfig struct {
func (n *EvalBuildProviderConfig) Eval(ctx EvalContext) (interface{}, error) {
cfg := *n.Config
// If we have a configuration set, then merge that in
// If we have an Input configuration set, then merge that in
if input := ctx.ProviderInput(n.Provider); input != nil {
// "input" is a map of the subset of config values that were known
// during the input walk, set by EvalInputProvider. Note that
@ -29,7 +29,7 @@ func (n *EvalBuildProviderConfig) Eval(ctx EvalContext) (interface{}, error) {
return nil, err
}
merged := cfg.raw.Merge(rc)
merged := rc.Merge(cfg.raw)
cfg = NewResourceConfig(merged)
}

View File

@ -37,7 +37,7 @@ func TestEvalBuildProviderConfig(t *testing.T) {
// We expect the provider config with the added input value
expected := map[string]interface{}{
"set_in_config": "input", // in practice, input map contains identical literals from config
"set_in_config": "config",
"set_in_config_and_parent": "config",
"computed_in_config": "config",
"set_by_input": "input",

View File

@ -1,24 +1,10 @@
package terraform
import (
"crypto/md5"
"encoding/hex"
"strings"
)
// PathCacheKey returns a cache key for a module path.
//
// TODO: test
func PathCacheKey(path []string) string {
// There is probably a better way to do this, but this is working for now.
// We just create an MD5 hash of all the MD5 hashes of all the path
// elements. This gets us the property that it is unique per ordering.
hash := md5.New()
for _, p := range path {
single := md5.Sum([]byte(p))
if _, err := hash.Write(single[:]); err != nil {
panic(err)
}
}
return hex.EncodeToString(hash.Sum(nil))
return strings.Join(path, "|")
}