From a7507e140d229744b9a71e20f991241600f47e3e Mon Sep 17 00:00:00 2001 From: James Bardin Date: Sun, 12 Apr 2020 11:26:44 -0400 Subject: [PATCH] parse module references as whole modules Module references, like resource references, need to always return the and object containing all instances in order to handle modules as single values, and to postpone index evaluation to when the expression as whole is evaluated. --- addrs/parse_ref.go | 17 ++++++++--------- addrs/parse_ref_test.go | 6 ++---- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/addrs/parse_ref.go b/addrs/parse_ref.go index cd8b114f6..eac77f306 100644 --- a/addrs/parse_ref.go +++ b/addrs/parse_ref.go @@ -120,10 +120,9 @@ func parseRef(traversal hcl.Traversal) (*Reference, tfdiags.Diagnostics) { return nil, diags } - // A traversal starting with "module" can either be a reference to - // an entire module instance or to a single output from a module - // instance, depending on what we find after this introducer. - + // A traversal starting with "module" can either be a reference to an + // entire module, or to a single output from a module instance, + // depending on what we find after this introducer. callInstance := ModuleCallInstance{ Call: ModuleCall{ Name: callName, @@ -132,12 +131,12 @@ func parseRef(traversal hcl.Traversal) (*Reference, tfdiags.Diagnostics) { } if len(remain) == 0 { - // Reference to an entire module instance. Might alternatively - // be a reference to a collection of instances of a particular - // module, but the caller will need to deal with that ambiguity - // since we don't have enough context here. + // Reference to an entire module. Might alternatively be a + // reference to a single instance of a particular module, but the + // caller will need to deal with that ambiguity since we don't have + // enough context here. return &Reference{ - Subject: callInstance, + Subject: callInstance.Call, SourceRange: tfdiags.SourceRangeFromHCL(callRange), Remaining: remain, }, diags diff --git a/addrs/parse_ref_test.go b/addrs/parse_ref_test.go index be1eb244e..233bf8685 100644 --- a/addrs/parse_ref_test.go +++ b/addrs/parse_ref_test.go @@ -281,10 +281,8 @@ func TestParseRef(t *testing.T) { { `module.foo`, &Reference{ - Subject: ModuleCallInstance{ - Call: ModuleCall{ - Name: "foo", - }, + Subject: ModuleCall{ + Name: "foo", }, SourceRange: tfdiags.SourceRange{ Start: tfdiags.SourcePos{Line: 1, Column: 1, Byte: 0},