diff --git a/docker/provider.go b/docker/provider.go index 64817899..2421f04a 100644 --- a/docker/provider.go +++ b/docker/provider.go @@ -215,20 +215,17 @@ func providerSetToRegistryAuth(authSet *schema.Set) (*AuthConfigs, error) { } filePath = strings.Replace(filePath, "~", usr.HomeDir, 1) } - r, err := os.Open(filePath) if err != nil { - return nil, fmt.Errorf("Error opening docker registry config file: %v", err) + continue } - c, err := loadConfigFile(r) if err != nil { - return nil, fmt.Errorf("Error parsing docker registry config json: %v", err) + continue } authFileConfig, err := c.GetAuthConfig(registryHostname) if err != nil { - return nil, fmt.Errorf("Couldn't find registry config for '%s' in file: %s", - registryHostname, filePath) + continue } authConfig.Username = authFileConfig.Username authConfig.Password = authFileConfig.Password diff --git a/docker/provider_test.go b/docker/provider_test.go index 720071dc..bc3e2455 100644 --- a/docker/provider_test.go +++ b/docker/provider_test.go @@ -2,8 +2,10 @@ package docker import ( "os/exec" + "regexp" "testing" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/terraform" ) @@ -24,6 +26,19 @@ func TestProvider(t *testing.T) { } } +func TestAccDockerProvider_WithIncompleteRegistryAuth(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDockerProviderWithIncompleteAuthConfig, + ExpectError: regexp.MustCompile(`401 Unauthorized`), + }, + }, + }) +} + func TestProvider_impl(t *testing.T) { var _ terraform.ResourceProvider = Provider() } @@ -47,3 +62,18 @@ func testAccPreCheck(t *testing.T) { t.Fatal(err) } } + +const testAccDockerProviderWithIncompleteAuthConfig = ` +provider "docker" { + alias = "private" + registry_auth { + address = "" + username = "" + password = "" + } +} +data "docker_registry_image" "foobar" { + provider = "docker.private" + name = "localhost:15000/helloworld:1.0" +} +`