AddMappedModule adds a reference to a module that was mapped to a CSV of keys, which duplicates the module in the template. We store a reference here so that we can resolve references like Content[0].Arn, which points to the first mapped instance of a Module called Content, with an Output called Arn
(copiedConfig *ModuleConfig)
| 253 | // that we can resolve references like Content[0].Arn, which points to the first |
| 254 | // mapped instance of a Module called Content, with an Output called Arn. |
| 255 | func (t *Template) AddMappedModule(copiedConfig *ModuleConfig) { |
| 256 | if t.ModuleMaps == nil { |
| 257 | t.ModuleMaps = make(map[string]*ModuleConfig) |
| 258 | } |
| 259 | t.ModuleMaps[copiedConfig.Name] = copiedConfig |
| 260 | keyName := copiedConfig.OriginalName + copiedConfig.MapKey |
| 261 | // Also add the name if referenced by key |
| 262 | t.ModuleMaps[keyName] = copiedConfig |
| 263 | |
| 264 | if t.ModuleMapNames == nil { |
| 265 | t.ModuleMapNames = make(map[string][]string) |
| 266 | } |
| 267 | originalName := copiedConfig.OriginalName |
| 268 | var mappedModules []string |
| 269 | var ok bool |
| 270 | if mappedModules, ok = t.ModuleMapNames[originalName]; !ok { |
| 271 | mappedModules = make([]string, 0) |
| 272 | } |
| 273 | if !slices.Contains(mappedModules, copiedConfig.Name) { |
| 274 | mappedModules = append(mappedModules, copiedConfig.Name) |
| 275 | } |
| 276 | t.ModuleMapNames[originalName] = mappedModules |
| 277 | } |
| 278 | |
| 279 | func (t *Template) AddResolvedModuleNode(n *yaml.Node) { |
| 280 | if t.ModuleResolved == nil { |