From 98cf28b02d20e947a249a2a21a187fde30c15bda Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 24 Apr 2020 10:43:53 -0400 Subject: [PATCH] 2 more tests that weren't correct Found 2 more tests that still had dangling empty modules, which are now fixed. --- terraform/context_apply_test.go | 10 +++------ terraform/eval_state.go | 6 +++--- terraform/evaluate.go | 38 --------------------------------- 3 files changed, 6 insertions(+), 48 deletions(-) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index e2add81e4..f87bb720c 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -2637,7 +2637,7 @@ func TestContext2Apply_orphanResource(t *testing.T) { Type: "test_thing", Name: "one", }.Absolute(addrs.RootModuleInstance) - s.SetResourceMeta(oneAddr, states.EachList, providerAddr) + s.SetResourceProvider(oneAddr, providerAddr) s.SetResourceInstanceCurrent(oneAddr.Instance(addrs.IntKey(0)), &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte(`{}`), @@ -6111,9 +6111,7 @@ func TestContext2Apply_destroyWithModuleVariableAndCount(t *testing.T) { //Test that things were destroyed actual := strings.TrimSpace(state.String()) expected := strings.TrimSpace(` - -module.child: - `) +`) if actual != expected { t.Fatalf("expected: \n%s\n\nbad: \n%s", expected, actual) } @@ -6269,9 +6267,7 @@ func TestContext2Apply_destroyWithModuleVariableAndCountNested(t *testing.T) { //Test that things were destroyed actual := strings.TrimSpace(state.String()) expected := strings.TrimSpace(` - -module.child.child2: - `) +`) if actual != expected { t.Fatalf("expected: \n%s\n\nbad: \n%s", expected, actual) } diff --git a/terraform/eval_state.go b/terraform/eval_state.go index d12adf374..c19d37801 100644 --- a/terraform/eval_state.go +++ b/terraform/eval_state.go @@ -475,7 +475,7 @@ func (n *EvalWriteResourceState) Eval(ctx EvalContext) (interface{}, error) { return nil, diags.Err() } - state.SetResourceMeta(n.Addr, states.EachList, n.ProviderAddr) + state.SetResourceProvider(n.Addr, n.ProviderAddr) expander.SetResourceCount(n.Addr.Module, n.Addr.Resource, count) case n.Config.ForEach != nil: @@ -487,11 +487,11 @@ func (n *EvalWriteResourceState) Eval(ctx EvalContext) (interface{}, error) { // This method takes care of all of the business logic of updating this // while ensuring that any existing instances are preserved, etc. - state.SetResourceMeta(n.Addr, states.EachMap, n.ProviderAddr) + state.SetResourceProvider(n.Addr, n.ProviderAddr) expander.SetResourceForEach(n.Addr.Module, n.Addr.Resource, forEach) default: - state.SetResourceMeta(n.Addr, states.NoEach, n.ProviderAddr) + state.SetResourceProvider(n.Addr, n.ProviderAddr) expander.SetResourceSingle(n.Addr.Module, n.Addr.Resource) } diff --git a/terraform/evaluate.go b/terraform/evaluate.go index 79397f1b7..128dd7a4c 100644 --- a/terraform/evaluate.go +++ b/terraform/evaluate.go @@ -4,7 +4,6 @@ import ( "fmt" "os" "path/filepath" - "strconv" "sync" "github.com/agext/levenshtein" @@ -803,43 +802,6 @@ func (d *evaluationStateData) getResourceSchema(addr addrs.Resource, providerAdd return schema } -// coerceInstanceKey attempts to convert the given key to the type expected -// for the given EachMode. -// -// If the key is already of the correct type or if it cannot be converted then -// it is returned verbatim. If conversion is required and possible, the -// converted value is returned. Callers should not try to determine if -// conversion was possible, should instead just check if the result is of -// the expected type. -func (d *evaluationStateData) coerceInstanceKey(key addrs.InstanceKey, mode states.EachMode) addrs.InstanceKey { - if key == addrs.NoKey { - // An absent key can't be converted - return key - } - - switch mode { - case states.NoEach: - // No conversions possible at all - return key - case states.EachMap: - if intKey, isInt := key.(addrs.IntKey); isInt { - return addrs.StringKey(strconv.Itoa(int(intKey))) - } - return key - case states.EachList: - if strKey, isStr := key.(addrs.StringKey); isStr { - i, err := strconv.Atoi(string(strKey)) - if err != nil { - return key - } - return addrs.IntKey(i) - } - return key - default: - return key - } -} - func (d *evaluationStateData) GetTerraformAttr(addr addrs.TerraformAttr, rng tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) { var diags tfdiags.Diagnostics switch addr.Name {