Process the Modules section of a template or module. Modifies t in place.
(t *cft.Template, n *yaml.Node, rootDir string, fs *embed.FS, parentModule *Module)
| 77 | // Process the Modules section of a template or module. |
| 78 | // Modifies t in place. |
| 79 | func processModulesSection(t *cft.Template, n *yaml.Node, |
| 80 | rootDir string, fs *embed.FS, parentModule *Module) error { |
| 81 | |
| 82 | // AWS CLI package Modules compatibility. |
| 83 | // This is basically the same as !Rain::Module but the modules are |
| 84 | // defined in a new Modules Section. |
| 85 | _, moduleSection, _ := s11n.GetMapValue(n, "Modules") |
| 86 | if moduleSection == nil { |
| 87 | return nil |
| 88 | } |
| 89 | HasModules = true |
| 90 | |
| 91 | if moduleSection.Kind != yaml.MappingNode { |
| 92 | return errors.New("the Modules section is not a mapping node") |
| 93 | } |
| 94 | |
| 95 | originalContent := moduleSection.Content |
| 96 | |
| 97 | // Duplicate module content that has a ForEach attribute |
| 98 | content, err := processMaps(originalContent, t, parentModule) |
| 99 | if err != nil { |
| 100 | return err |
| 101 | } |
| 102 | |
| 103 | // Replace the original Modules content |
| 104 | moduleSection.Content = content |
| 105 | |
| 106 | for i := 0; i < len(content); i += 2 { |
| 107 | name := content[i].Value |
| 108 | moduleConfig, err := t.ParseModuleConfig(name, content[i+1]) |
| 109 | if err != nil { |
| 110 | return err |
| 111 | } |
| 112 | moduleConfig.ParentRootDir = rootDir |
| 113 | |
| 114 | baseUri := "" |
| 115 | uri := moduleConfig.Source |
| 116 | |
| 117 | moduleContent, err := getModuleContent(rootDir, t, fs, baseUri, uri) |
| 118 | if err != nil { |
| 119 | return err |
| 120 | } |
| 121 | |
| 122 | parsed, err := parseModule(moduleContent.Content, |
| 123 | moduleContent.NewRootDir, fs) |
| 124 | if err != nil { |
| 125 | return err |
| 126 | } |
| 127 | |
| 128 | // Transform the parsed module content |
| 129 | outputNode := node.MakeMapping() |
| 130 | |
| 131 | err = processModule( |
| 132 | parsed, |
| 133 | outputNode, |
| 134 | t, |
| 135 | moduleConfig, |
| 136 | parentModule) |
no test coverage detected