{"record":{"id":"b596a85b4b69ce06","repo":"hashicorp/terraform","slug":"subdir-q-matches-multiple-paths","errorCode":null,"errorMessage":"subdir %q matches multiple paths","messagePattern":"subdir %q matches multiple paths","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/getmodules/moduleaddrs/subdir.go","lineNumber":93,"sourceCode":"// to select the contents of the single directory at the root of a conventional\n// tar archive but it doesn't actually know the exact name of that directory.\n// In that case it might specify a subdir of just \"*\", which this function\n// will then expand into the single subdirectory found inside instDir, or\n// return an error if the result would be ambiguous.\nfunc ExpandSubdirGlobs(instDir string, subDir string) (string, error) {\n\tpattern := filepath.Join(instDir, subDir)\n\n\tmatches, err := filepath.Glob(pattern)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tif len(matches) == 0 {\n\t\treturn \"\", fmt.Errorf(\"subdir %q not found\", subDir)\n\t}\n\n\tif len(matches) > 1 {\n\t\treturn \"\", fmt.Errorf(\"subdir %q matches multiple paths\", subDir)\n\t}\n\n\treturn matches[0], nil\n}\n","sourceCodeStart":75,"sourceCodeEnd":98,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/getmodules/moduleaddrs/subdir.go#L75-L98","documentation":"Returned by ExpandSubdirGlobs when filepath.Glob of instDir/subDir yields more than one match. The wildcard '*' is meant to collapse a single nested directory automatically; multiple matches make the choice ambiguous, so the function refuses to guess. The %q is the subdir pattern.","triggerScenarios":"A subdir pattern containing '*' (or matching multiple entries) resolves to several directories inside the extracted package, e.g. an archive with several top-level folders when the source expected exactly one.","commonSituations":"Module archive ships multiple top-level directories; ref changed to one with a different layout; wildcard used where a concrete path should be.","solutions":["Replace the wildcard with the concrete subdir path you want.","Pin the module ref to a version whose archive has a single top-level directory.","Re-package the source so the wildcard is unambiguous."],"exampleFix":"# before (multiple top-level dirs -> ambiguous)\nsource = \"github.com/org/repo//*\"\n\n# after (concrete subdir)\nsource = \"github.com/org/repo//modules/vpc\"","handlingStrategy":"validation","validationCode":"// Detect ambiguous wildcards before expansion.\n// matches, _ := filepath.Glob(filepath.Join(instDir, subDir))\n// if len(matches) > 1 {\n//     return fmt.Errorf(\"subdir %q is ambiguous: %v\", subDir, matches)\n// }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid '*' in subdirs; specify concrete paths.","Pin module refs whose archives have a single top-level directory.","Re-package archives to remove top-level ambiguity."],"tags":["subdir","module-installation","wildcard","archive"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}