github.com/chalford/terraform@v0.3.7-0.20150113080010-a78c69a8c81f/config/module/detect_file.go (about)

     1  package module
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  )
     7  
     8  // FileDetector implements Detector to detect file paths.
     9  type FileDetector struct{}
    10  
    11  func (d *FileDetector) Detect(src, pwd string) (string, bool, error) {
    12  	if len(src) == 0 {
    13  		return "", false, nil
    14  	}
    15  
    16  	// Make sure we're using "/" even on Windows. URLs are "/"-based.
    17  	src = filepath.ToSlash(src)
    18  	if !filepath.IsAbs(src) {
    19  		if pwd == "" {
    20  			return "", true, fmt.Errorf(
    21  				"relative paths require a module with a pwd")
    22  		}
    23  
    24  		src = filepath.Join(pwd, src)
    25  	}
    26  
    27  	// Make sure that we don't start with "/" since we add that below
    28  	if src[0] == '/' {
    29  		src = src[1:]
    30  	}
    31  
    32  	return fmt.Sprintf("file:///%s", src), true, nil
    33  }