getModules returns the modules from the modules file if it exists. It returns nil if the file does not exist. Modules become available after terraform init.
(files tfpath.Layout)
| 66 | // It returns nil if the file does not exist. |
| 67 | // Modules become available after terraform init. |
| 68 | func getModules(files tfpath.Layout) ([]*proto.Module, error) { |
| 69 | filePath := files.ModulesFilePath() |
| 70 | if _, err := os.Stat(filePath); os.IsNotExist(err) { |
| 71 | return nil, nil |
| 72 | } |
| 73 | modules, err := parseModulesFile(filePath) |
| 74 | if err != nil { |
| 75 | return nil, xerrors.Errorf("parse modules file: %w", err) |
| 76 | } |
| 77 | filteredModules := []*proto.Module{} |
| 78 | for _, m := range modules { |
| 79 | // Empty string means root module. It's always present, so we skip it. |
| 80 | if m.Source == "" { |
| 81 | continue |
| 82 | } |
| 83 | filteredModules = append(filteredModules, m) |
| 84 | } |
| 85 | return filteredModules, nil |
| 86 | } |
| 87 | |
| 88 | func GetModulesArchive(root fs.FS) ([]byte, []string, error) { |
| 89 | return GetModulesArchiveWithLimit(root, MaximumModuleArchiveSize) |
no test coverage detected