terraform/config/module/detect_file.go

26 lines
460 B
Go

package module
import (
"fmt"
"path/filepath"
)
// FileDetector implements Detector to detect file paths.
type FileDetector struct{}
func (d *FileDetector) Detect(src, pwd string) (string, bool, error) {
if len(src) == 0 {
return "", false, nil
}
if !filepath.IsAbs(src) {
if pwd == "" {
return "", true, fmt.Errorf(
"relative paths require a module with a pwd")
}
src = filepath.Join(pwd, src)
}
return fmtFileURL(src), true, nil
}