From ab350289abb8fa4137e5a2c8fbcab32f887a310a Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 29 Jun 2021 15:06:00 -0700 Subject: [PATCH] addrs: Rename AbsModuleCallOutput to ModuleCallInstanceOutput The previous name didn't fit with the naming scheme for addrs types: The "Abs" prefix typically means that it's an addrs.ModuleInstance combined with whatever type name appears after "Abs", but this is instead a ModuleCallOutput combined with an InstanceKey, albeit structured the other way around for convenience, and so the expected name for this would be the suffix "Instance". We don't have an "Abs" type corresponding with this one because it would represent no additional information than AbsOutputValue. --- internal/addrs/module_call.go | 10 +++++----- internal/addrs/output_value.go | 4 ++-- internal/addrs/parse_ref.go | 2 +- internal/addrs/parse_ref_test.go | 8 ++++---- internal/command/jsonconfig/expression.go | 4 ++-- internal/lang/data_test.go | 2 +- internal/lang/eval.go | 2 +- internal/terraform/evaluate_valid.go | 2 +- internal/terraform/transform_reference.go | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/internal/addrs/module_call.go b/internal/addrs/module_call.go index 02163ef7d..bfaf66e96 100644 --- a/internal/addrs/module_call.go +++ b/internal/addrs/module_call.go @@ -72,9 +72,9 @@ func (m ModuleCallOutput) String() string { return fmt.Sprintf("%s.%s", m.Call.String(), m.Name) } -// AbsModuleCallOutput is the address of a particular named output produced by +// ModuleCallInstanceOutput is the address of a particular named output produced by // an instance of a module call. -type AbsModuleCallOutput struct { +type ModuleCallInstanceOutput struct { referenceable Call ModuleCallInstance Name string @@ -82,21 +82,21 @@ type AbsModuleCallOutput struct { // ModuleCallOutput returns the referenceable ModuleCallOutput for this // particular instance. -func (co AbsModuleCallOutput) ModuleCallOutput() ModuleCallOutput { +func (co ModuleCallInstanceOutput) ModuleCallOutput() ModuleCallOutput { return ModuleCallOutput{ Call: co.Call.Call, Name: co.Name, } } -func (co AbsModuleCallOutput) String() string { +func (co ModuleCallInstanceOutput) String() string { return fmt.Sprintf("%s.%s", co.Call.String(), co.Name) } // AbsOutputValue returns the absolute output value address that corresponds // to the receving module call output address, once resolved in the given // calling module. -func (co AbsModuleCallOutput) AbsOutputValue(caller ModuleInstance) AbsOutputValue { +func (co ModuleCallInstanceOutput) AbsOutputValue(caller ModuleInstance) AbsOutputValue { moduleAddr := co.Call.ModuleInstance(caller) return moduleAddr.OutputValue(co.Name) } diff --git a/internal/addrs/output_value.go b/internal/addrs/output_value.go index d0dfca56c..ce46b5248 100644 --- a/internal/addrs/output_value.go +++ b/internal/addrs/output_value.go @@ -66,13 +66,13 @@ func (v AbsOutputValue) Equal(o AbsOutputValue) bool { // // The root module does not have a call, and so this method cannot be used // with outputs in the root module, and will panic in that case. -func (v AbsOutputValue) ModuleCallOutput() (ModuleInstance, AbsModuleCallOutput) { +func (v AbsOutputValue) ModuleCallOutput() (ModuleInstance, ModuleCallInstanceOutput) { if v.Module.IsRoot() { panic("ReferenceFromCall used with root module output") } caller, call := v.Module.CallInstance() - return caller, AbsModuleCallOutput{ + return caller, ModuleCallInstanceOutput{ Call: call, Name: v.OutputValue.Name, } diff --git a/internal/addrs/parse_ref.go b/internal/addrs/parse_ref.go index 9dbeb8966..bb6842979 100644 --- a/internal/addrs/parse_ref.go +++ b/internal/addrs/parse_ref.go @@ -191,7 +191,7 @@ func parseRef(traversal hcl.Traversal) (*Reference, tfdiags.Diagnostics) { if attrTrav, ok := remain[0].(hcl.TraverseAttr); ok { remain = remain[1:] return &Reference{ - Subject: AbsModuleCallOutput{ + Subject: ModuleCallInstanceOutput{ Name: attrTrav.Name, Call: callInstance, }, diff --git a/internal/addrs/parse_ref_test.go b/internal/addrs/parse_ref_test.go index 37b1bfce0..52c9b2cd3 100644 --- a/internal/addrs/parse_ref_test.go +++ b/internal/addrs/parse_ref_test.go @@ -294,7 +294,7 @@ func TestParseRef(t *testing.T) { { `module.foo.bar`, &Reference{ - Subject: AbsModuleCallOutput{ + Subject: ModuleCallInstanceOutput{ Call: ModuleCallInstance{ Call: ModuleCall{ Name: "foo", @@ -312,7 +312,7 @@ func TestParseRef(t *testing.T) { { `module.foo.bar.baz`, &Reference{ - Subject: AbsModuleCallOutput{ + Subject: ModuleCallInstanceOutput{ Call: ModuleCallInstance{ Call: ModuleCall{ Name: "foo", @@ -355,7 +355,7 @@ func TestParseRef(t *testing.T) { { `module.foo["baz"].bar`, &Reference{ - Subject: AbsModuleCallOutput{ + Subject: ModuleCallInstanceOutput{ Call: ModuleCallInstance{ Call: ModuleCall{ Name: "foo", @@ -374,7 +374,7 @@ func TestParseRef(t *testing.T) { { `module.foo["baz"].bar.boop`, &Reference{ - Subject: AbsModuleCallOutput{ + Subject: ModuleCallInstanceOutput{ Call: ModuleCallInstance{ Call: ModuleCall{ Name: "foo", diff --git a/internal/command/jsonconfig/expression.go b/internal/command/jsonconfig/expression.go index 52ff927c2..0244d73d0 100644 --- a/internal/command/jsonconfig/expression.go +++ b/internal/command/jsonconfig/expression.go @@ -68,9 +68,9 @@ func marshalExpression(ex hcl.Expression) expression { // Include the resource, without the key varString = append(varString, ref.Subject.(addrs.ResourceInstance).Resource.String()) } - case addrs.AbsModuleCallOutput: + case addrs.ModuleCallInstanceOutput: // Include the module name, without the output name - varString = append(varString, ref.Subject.(addrs.AbsModuleCallOutput).Call.String()) + varString = append(varString, ref.Subject.(addrs.ModuleCallInstanceOutput).Call.String()) } } ret.References = varString diff --git a/internal/lang/data_test.go b/internal/lang/data_test.go index 28f7bdc0c..e86a85618 100644 --- a/internal/lang/data_test.go +++ b/internal/lang/data_test.go @@ -47,7 +47,7 @@ func (d *dataForTests) GetModule(addr addrs.ModuleCall, rng tfdiags.SourceRange) return d.Modules[addr.String()], nil } -func (d *dataForTests) GetModuleInstanceOutput(addr addrs.AbsModuleCallOutput, rng tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) { +func (d *dataForTests) GetModuleInstanceOutput(addr addrs.ModuleCallInstanceOutput, rng tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) { // This will panic if the module object does not have the requested attribute obj := d.Modules[addr.Call.String()] return obj.GetAttr(addr.Name), nil diff --git a/internal/lang/eval.go b/internal/lang/eval.go index 303a8b3ac..c1faca9e6 100644 --- a/internal/lang/eval.go +++ b/internal/lang/eval.go @@ -341,7 +341,7 @@ func (s *Scope) evalContext(refs []*addrs.Reference, selfAddr addrs.Referenceabl rawSubj = addr.ContainingResource() case addrs.ModuleCallInstance: rawSubj = addr.Call - case addrs.AbsModuleCallOutput: + case addrs.ModuleCallInstanceOutput: rawSubj = addr.Call.Call } diff --git a/internal/terraform/evaluate_valid.go b/internal/terraform/evaluate_valid.go index 21adc77f1..68943a842 100644 --- a/internal/terraform/evaluate_valid.go +++ b/internal/terraform/evaluate_valid.go @@ -91,7 +91,7 @@ func (d *evaluationStateData) staticValidateReference(ref *addrs.Reference, self return d.staticValidateModuleCallReference(modCfg, addr, ref.Remaining, ref.SourceRange) case addrs.ModuleCallInstance: return d.staticValidateModuleCallReference(modCfg, addr.Call, ref.Remaining, ref.SourceRange) - case addrs.AbsModuleCallOutput: + case addrs.ModuleCallInstanceOutput: // This one is a funny one because we will take the output name referenced // and use it to fake up a "remaining" that would make sense for the // module call itself, rather than for the specific output, and then diff --git a/internal/terraform/transform_reference.go b/internal/terraform/transform_reference.go index fea90592e..fe64e3707 100644 --- a/internal/terraform/transform_reference.go +++ b/internal/terraform/transform_reference.go @@ -296,7 +296,7 @@ func (m ReferenceMap) References(v dag.Vertex) []dag.Vertex { subject = ri.ContainingResource() case addrs.ResourceInstancePhase: subject = ri.ContainingResource() - case addrs.AbsModuleCallOutput: + case addrs.ModuleCallInstanceOutput: subject = ri.ModuleCallOutput() case addrs.ModuleCallInstance: subject = ri.Call