MCPcopy Create free account
hub / github.com/aws-cloudformation/rain / ProcessOutputs

Method ProcessOutputs

cft/pkg/outputs.go:20–89  ·  view source on GitHub ↗

processModuleOutputs looks for any references in the parent template to the module's outputs and replaces them.

()

Source from the content-addressed store, hash-verified

18// processModuleOutputs looks for any references in the parent
19// template to the module's outputs and replaces them.
20func (module *Module) ProcessOutputs() error {
21
22 // Visit each node in the parent template. If we see a Ref, Sub, or
23 // GetAtt that points to one of this module's output values,
24 // Replace the reference with that value.
25
26 if module == nil {
27 return fmt.Errorf("module is nil")
28 }
29
30 if module.Config == nil {
31 return fmt.Errorf("module config is nil")
32 }
33
34 if module.OutputsNode == nil {
35 return nil
36 }
37
38 // Resolve output values first
39 for i := 0; i < len(module.OutputsNode.Content); i += 2 {
40 outputNode := module.OutputsNode.Content[i+1]
41 module.Resolve(outputNode)
42 }
43
44 t := module.ParentTemplate
45
46 // Store the Outputs node on the template for later use
47 if t.ModuleOutputs == nil {
48 t.ModuleOutputs = make(map[string]*yaml.Node)
49 }
50 t.ModuleOutputs[module.Config.Name] = module.OutputsNode
51
52 // Iterate over module outputs
53 for outputName, outputVal := range module.Outputs() {
54
55 var err error
56
57 // Use a visitor function to find Fn::Sub or Fn::GetAtt that points to
58 // this output. Refs can't point to module outputs since you need
59 // ModuleName.OutputName
60 vf := func(v *visitor.Visitor) {
61 n := v.GetYamlNode()
62 if n.Kind != yaml.MappingNode || len(n.Content) != 2 {
63 return
64 }
65 switch n.Content[0].Value {
66 case string(cft.Sub):
67 err = module.OutputSub(outputName, outputVal, n)
68 if err != nil {
69 v.Stop()
70 return
71 }
72 case string(cft.GetAtt):
73 err = module.OutputGetAtt(outputName, outputVal, n)
74 if err != nil {
75 v.Stop()
76 return
77 }

Callers 1

processModuleFunction · 0.95

Calls 8

ResolveMethod · 0.95
OutputsMethod · 0.95
OutputSubMethod · 0.95
OutputGetAttMethod · 0.95
NewVisitorFunction · 0.92
GetYamlNodeMethod · 0.80
StopMethod · 0.80
VisitMethod · 0.80

Tested by

no test coverage detected