From 6c8714dc4a3a831c07ae4cddb1757fbe031c3ecc Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Wed, 10 Aug 2022 08:32:34 -0500 Subject: [PATCH] fix: Check the operating system for determining the default Docker socket (#427) Windows doesn't use `/var/run/docker.sock`, so this provider didn't work out of the box. --- internal/provider/provider.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 51f4902a..779c2d34 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -7,6 +7,7 @@ import ( "log" "os" "os/user" + "runtime" "strings" "github.com/docker/cli/cli/config/configfile" @@ -39,9 +40,17 @@ func New(version string) func() *schema.Provider { p := &schema.Provider{ Schema: map[string]*schema.Schema{ "host": { - Type: schema.TypeString, - Required: true, - DefaultFunc: schema.EnvDefaultFunc("DOCKER_HOST", "unix:///var/run/docker.sock"), + Type: schema.TypeString, + Required: true, + DefaultFunc: func() (interface{}, error) { + if v := os.Getenv("DOCKER_HOST"); v != "" { + return v, nil + } + if runtime.GOOS == "windows" { + return "npipe:////./pipe/docker_engine", nil + } + return "unix:///var/run/docker.sock", nil + }, Description: "The Docker daemon address", }, "ssh_opts": {