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

Method ParseModuleConfig

cft/module_config.go:81–146  ·  view source on GitHub ↗

parseModuleConfig parses a single module configuration from the Modules section in the template

(
	name string, n *yaml.Node)

Source from the content-addressed store, hash-verified

79// parseModuleConfig parses a single module configuration
80// from the Modules section in the template
81func (t *Template) ParseModuleConfig(
82 name string, n *yaml.Node) (*ModuleConfig, error) {
83
84 m := &ModuleConfig{}
85 m.Name = name
86 m.Node = n
87
88 // Handle Fn::ForEach modules
89 if strings.HasPrefix(name, ForEach) && n.Kind == yaml.SequenceNode {
90 if len(n.Content) != 3 {
91 msg := "expected %s len 3, got %d"
92 return nil, fmt.Errorf(msg, name, len(n.Content))
93 }
94
95 m.FnForEach = &FnForEach{}
96
97 loopName := strings.Replace(name, ForEach, "", 1)
98 loopName = strings.Replace(loopName, ":", "", -1)
99 m.FnForEach.LoopName = loopName
100
101 m.Name = loopName // TODO: ?
102
103 m.FnForEach.Identifier = n.Content[0].Value
104 m.FnForEach.Collection = n.Content[1]
105 outputKeyValue := n.Content[2]
106
107 if outputKeyValue.Kind != yaml.MappingNode ||
108 len(outputKeyValue.Content) != 2 ||
109 outputKeyValue.Content[1].Kind != yaml.MappingNode {
110 msg := "invalid %s, expected OutputKey: OutputValue mapping"
111 return nil, fmt.Errorf(msg, name)
112 }
113
114 m.FnForEach.OutputKey = outputKeyValue.Content[0].Value
115 m.Node = outputKeyValue.Content[1]
116 m.FnForEach.OutputValue = m.Node
117 n = m.Node
118 m.Map = m.FnForEach.Collection
119
120 config.Debugf("ModuleConfig.FnForEach: %+v", m.FnForEach)
121
122 }
123
124 if n.Kind != yaml.MappingNode {
125 config.Debugf("ParseModuleConfig %s: %s", name, node.ToSJson(n))
126 return nil, errors.New("not a mapping node")
127 }
128
129 content := n.Content
130 for i := 0; i < len(content); i += 2 {
131 attr := content[i].Value
132 val := content[i+1]
133 switch attr {
134 case Source:
135 m.Source = val.Value
136 case Properties:
137 m.PropertiesNode = val
138 case Overrides:

Callers 6

TestParseModuleConfigFunction · 0.95
FnInvokeMethod · 0.80
processMapsFunction · 0.80
processModulesSectionFunction · 0.80

Calls 2

DebugfFunction · 0.92
ToSJsonFunction · 0.92

Tested by 2

TestParseModuleConfigFunction · 0.76