From d8f4c1f618de1d81894182465a1d6984846cb30e Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 16 Oct 2017 13:42:55 -0400 Subject: [PATCH] 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. --- terraform/eval_provider.go | 4 ++-- terraform/eval_provider_test.go | 2 +- terraform/path.go | 18 ++---------------- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/terraform/eval_provider.go b/terraform/eval_provider.go index 556588b590..e42f1c0dc3 100644 --- a/terraform/eval_provider.go +++ b/terraform/eval_provider.go @@ -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) } diff --git a/terraform/eval_provider_test.go b/terraform/eval_provider_test.go index 43653a7b76..000dc51287 100644 --- a/terraform/eval_provider_test.go +++ b/terraform/eval_provider_test.go @@ -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", diff --git a/terraform/path.go b/terraform/path.go index ca99685ad3..51dd4122bb 100644 --- a/terraform/path.go +++ b/terraform/path.go @@ -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, "|") }