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

Function ProcessOutputArrays

cft/pkg/outputs.go:287–357  ·  view source on GitHub ↗

After processing normal outputs, go back and look for array references like Content[].Arn. Values for these should be stored on the template.

(t *cft.Template)

Source from the content-addressed store, hash-verified

285// like Content[].Arn. Values for these should be stored on the
286// template.
287func ProcessOutputArrays(t *cft.Template) error {
288 if t == nil {
289 return errors.New("t is nil")
290 }
291
292 var err error
293
294 vf := func(v *visitor.Visitor) {
295 // Look for A[].B
296 // Get t.ModuleOutputs for all of them, convert to Sequence
297
298 n := v.GetYamlNode()
299 if n.Kind != yaml.MappingNode || len(n.Content) != 2 {
300 return
301 }
302
303 if n.Content[0].Value != string(cft.GetAtt) {
304 return
305 }
306
307 getatt := n.Content[1]
308 if getatt.Kind != yaml.SequenceNode || len(getatt.Content) != 2 {
309 err = fmt.Errorf("invalid getatt: %s", node.YamlStr(getatt))
310 v.Stop()
311 return
312 }
313
314 if !strings.Contains(getatt.Content[0].Value, "[]") {
315 return
316 }
317
318 moduleName := strings.Replace(getatt.Content[0].Value, "[]", "", 1)
319 outputName := getatt.Content[1].Value
320
321 names, ok := t.ModuleMapNames[moduleName]
322 if !ok {
323 err = fmt.Errorf("module names not found for %s", moduleName)
324 v.Stop()
325 return
326 }
327
328 items := make([]*yaml.Node, 0)
329 for _, name := range names {
330 outputs, ok := t.ModuleOutputs[name]
331 if !ok {
332 err = fmt.Errorf("%s not found in ModuleOutputs", name)
333 v.Stop()
334 return
335 }
336 _, o, _ := s11n.GetMapValue(outputs, outputName)
337 if o == nil {
338 err = fmt.Errorf("%s not found in Outputs for %s", outputName, name)
339 v.Stop()
340 return
341 }
342 _, val, _ := s11n.GetMapValue(o, "Value")
343 if val == nil {
344 err = fmt.Errorf("module output %s.%s missing Value", name, outputName)

Callers 1

processModulesSectionFunction · 0.85

Calls 6

YamlStrFunction · 0.92
GetMapValueFunction · 0.92
NewVisitorFunction · 0.92
GetYamlNodeMethod · 0.80
StopMethod · 0.80
VisitMethod · 0.80

Tested by

no test coverage detected