From 02167dcfe4666ab010678c8579185df6c320e312 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 15 Jun 2020 20:45:23 -0400 Subject: [PATCH 1/3] test whole module reference from module var this reference isn't being connected properly --- terraform/context_plan_test.go | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/terraform/context_plan_test.go b/terraform/context_plan_test.go index 2c2282d93..9dfddceea 100644 --- a/terraform/context_plan_test.go +++ b/terraform/context_plan_test.go @@ -5947,3 +5947,48 @@ resource "aws_instance" "foo" { t.Errorf("missing %s change for %s", action, res) } } + +func TestContext2Plan_moduleRefIndex(t *testing.T) { + m := testModuleInline(t, map[string]string{ + "main.tf": ` +module "mod" { + for_each = { + a = "thing" + } + in = null + source = "./mod" +} + +module "single" { + source = "./mod" + in = module.mod["a"] +} +`, + "mod/main.tf": ` +variable "in" { +} + +output "out" { + value = "foo" +} + +resource "aws_instance" "foo" { +} +`, + }) + + p := testProvider("aws") + p.DiffFn = testDiffFn + + ctx := testContext2(t, &ContextOpts{ + Config: m, + Providers: map[addrs.Provider]providers.Factory{ + addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p), + }, + }) + + _, diags := ctx.Plan() + if diags.HasErrors() { + t.Fatal(diags.ErrWithWarnings()) + } +} From d6ca469124356061a087d33e5f8a4fb5f54b8434 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 15 Jun 2020 20:46:03 -0400 Subject: [PATCH 2/3] module variables can't be referenced as a module --- terraform/node_module_variable.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/terraform/node_module_variable.go b/terraform/node_module_variable.go index c1ec01e27..e0d007f59 100644 --- a/terraform/node_module_variable.go +++ b/terraform/node_module_variable.go @@ -95,11 +95,7 @@ func (n *nodeExpandModuleVariable) ReferenceOutside() (selfPath, referencePath a // GraphNodeReferenceable func (n *nodeExpandModuleVariable) ReferenceableAddrs() []addrs.Referenceable { - // FIXME: References for module variables probably need to be thought out a bit more - // Otherwise, we can reference the output via the address itself, or the - // module call - _, call := n.Module.Call() - return []addrs.Referenceable{n.Addr, call} + return []addrs.Referenceable{n.Addr} } // RemovableIfNotTargeted From 7154c61f0b3e09a879c20d445235233b2741fd90 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 15 Jun 2020 20:46:53 -0400 Subject: [PATCH 3/3] reduce module instances refs to the module call There aren't going to be any nodes specifically for module call instances during plan, so we have to switch the reference subject to the general module call. --- terraform/transform_reference.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/terraform/transform_reference.go b/terraform/transform_reference.go index 94659e380..6a0ee98fa 100644 --- a/terraform/transform_reference.go +++ b/terraform/transform_reference.go @@ -303,6 +303,8 @@ func (m ReferenceMap) References(v dag.Vertex) []dag.Vertex { subject = ri.ContainingResource() case addrs.AbsModuleCallOutput: subject = ri.ModuleCallOutput() + case addrs.ModuleCallInstance: + subject = ri.Call default: log.Printf("[WARN] ReferenceTransformer: reference not found: %q", subject) continue