diff --git a/command/apply_test.go b/command/apply_test.go index 6c8643b871..0506b49d67 100644 --- a/command/apply_test.go +++ b/command/apply_test.go @@ -1124,7 +1124,7 @@ func TestApply_disableBackup(t *testing.T) { } func testHttpServer(t *testing.T) net.Listener { - ln, err := net.Listen("tcp", ":0") + ln, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { t.Fatalf("err: %s", err) } @@ -1142,7 +1142,7 @@ func testHttpServer(t *testing.T) net.Listener { func testHttpHandlerHeader(w http.ResponseWriter, r *http.Request) { var url url.URL url.Scheme = "file" - url.Path = testFixturePath("init") + url.Path = filepath.ToSlash(testFixturePath("init")) w.Header().Add("X-Terraform-Get", url.String()) w.WriteHeader(200) diff --git a/config/module/detect.go b/config/module/detect.go index bdf54f9f80..f70e69a478 100644 --- a/config/module/detect.go +++ b/config/module/detect.go @@ -38,10 +38,10 @@ func Detect(src string, pwd string) (string, error) { // Separate out the subdir if there is one, we don't pass that to detect getSrc, subDir := getDirSubdir(getSrc) - u, err := url.Parse(getSrc) + u, err := urlParse(getSrc) if err == nil && u.Scheme != "" { // Valid URL - return src, nil + return u.String(), nil } for _, d := range Detectors { diff --git a/config/module/url_helper.go b/config/module/url_helper.go index 061496270a..58c4a8967e 100644 --- a/config/module/url_helper.go +++ b/config/module/url_helper.go @@ -9,8 +9,13 @@ import ( func urlParse(rawURL string) (*url.URL, error) { if runtime.GOOS == "windows" { - // Make sure we're using "/" on Windows. URLs are "/"-based. - rawURL = filepath.ToSlash(rawURL) + if len(rawURL) > 1 && rawURL[1] == ':' { + // Assume we're dealing with a file path. + rawURL = fmtFileURL(rawURL) + } else { + // Make sure we're using "/" on Windows. URLs are "/"-based. + rawURL = filepath.ToSlash(rawURL) + } } u, err := url.Parse(rawURL) if err != nil {