aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/terraform/addrs/output_value.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/addrs/output_value.go')
-rw-r--r--vendor/github.com/hashicorp/terraform/addrs/output_value.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/addrs/output_value.go b/vendor/github.com/hashicorp/terraform/addrs/output_value.go
new file mode 100644
index 0000000..bcd923a
--- /dev/null
+++ b/vendor/github.com/hashicorp/terraform/addrs/output_value.go
@@ -0,0 +1,75 @@
1package addrs
2
3import (
4 "fmt"
5)
6
7// OutputValue is the address of an output value, in the context of the module
8// that is defining it.
9//
10// This is related to but separate from ModuleCallOutput, which represents
11// a module output from the perspective of its parent module. Since output
12// values cannot be represented from the module where they are defined,
13// OutputValue is not Referenceable, while ModuleCallOutput is.
14type OutputValue struct {
15 Name string
16}
17
18func (v OutputValue) String() string {
19 return "output." + v.Name
20}
21
22// Absolute converts the receiver into an absolute address within the given
23// module instance.
24func (v OutputValue) Absolute(m ModuleInstance) AbsOutputValue {
25 return AbsOutputValue{
26 Module: m,
27 OutputValue: v,
28 }
29}
30
31// AbsOutputValue is the absolute address of an output value within a module instance.
32//
33// This represents an output globally within the namespace of a particular
34// configuration. It is related to but separate from ModuleCallOutput, which
35// represents a module output from the perspective of its parent module.
36type AbsOutputValue struct {
37 Module ModuleInstance
38 OutputValue OutputValue
39}
40
41// OutputValue returns the absolute address of an output value of the given
42// name within the receiving module instance.
43func (m ModuleInstance) OutputValue(name string) AbsOutputValue {
44 return AbsOutputValue{
45 Module: m,
46 OutputValue: OutputValue{
47 Name: name,
48 },
49 }
50}
51
52func (v AbsOutputValue) String() string {
53 if v.Module.IsRoot() {
54 return v.OutputValue.String()
55 }
56 return fmt.Sprintf("%s.%s", v.Module.String(), v.OutputValue.String())
57}
58
59// ModuleCallOutput converts an AbsModuleOutput into a ModuleCallOutput,
60// returning also the module instance that the ModuleCallOutput is relative
61// to.
62//
63// The root module does not have a call, and so this method cannot be used
64// with outputs in the root module, and will panic in that case.
65func (v AbsOutputValue) ModuleCallOutput() (ModuleInstance, ModuleCallOutput) {
66 if v.Module.IsRoot() {
67 panic("ReferenceFromCall used with root module output")
68 }
69
70 caller, call := v.Module.CallInstance()
71 return caller, ModuleCallOutput{
72 Call: call,
73 Name: v.OutputValue.Name,
74 }
75}