diff --git a/.github/workflows/acc-test.yaml b/.github/workflows/acc-test.yaml index 28b77352..262b9459 100644 --- a/.github/workflows/acc-test.yaml +++ b/.github/workflows/acc-test.yaml @@ -25,7 +25,6 @@ jobs: fail-fast: false matrix: terraform_version: - - "0.15.x" - "1.8.x" resource_type: - "TestAccDockerConfig" diff --git a/docs/index.md b/docs/index.md index 9a4c76b5..2213cf16 100644 --- a/docs/index.md +++ b/docs/index.md @@ -172,7 +172,7 @@ Required: Optional: - `auth_disabled` (Boolean) Setting this to `true` will tell the provider that this registry does not need authentication. Due to the docker internals, the provider will use dummy credentials (see https://github.com/kreuzwerker/terraform-provider-docker/issues/470 for more information). Defaults to `false`. -- `config_file` (String) Path to docker json file for registry auth. Defaults to `~/.docker/config.json`. If `DOCKER_CONFIG` is set, the value of `DOCKER_CONFIG` is used as the path. `config_file` has predencen over all other options. +- `config_file` (String) Path to docker json file for registry auth. Defaults to `~/.docker/config.json`. If `DOCKER_CONFIG` env variable is set, the value of `DOCKER_CONFIG` is used as the path. `DOCKER_CONFIG` can be set to a directory (as per Docker CLI) or a file path directly. `config_file` has precedence over all other options. - `config_file_content` (String) Plain content of the docker json file for registry auth. `config_file_content` has precedence over username/password. - `password` (String, Sensitive) Password for the registry. Defaults to `DOCKER_REGISTRY_PASS` env variable if set. - `username` (String) Username for the registry. Defaults to `DOCKER_REGISTRY_USER` env variable if set. \ No newline at end of file diff --git a/internal/provider/framework_provider.go b/internal/provider/framework_provider.go index 7f9e0c1d..4fa8954d 100644 --- a/internal/provider/framework_provider.go +++ b/internal/provider/framework_provider.go @@ -96,7 +96,7 @@ func (p *frameworkProvider) Schema(ctx context.Context, req provider.SchemaReque Sensitive: true, }, "config_file": schema.StringAttribute{ - MarkdownDescription: "Path to docker json file for registry auth. Defaults to `~/.docker/config.json`. If `DOCKER_CONFIG` is set, the value of `DOCKER_CONFIG` is used as the path. `config_file` has predencen over all other options.", + MarkdownDescription: "Path to docker json file for registry auth. Defaults to `~/.docker/config.json`. If `DOCKER_CONFIG` env variable is set, the value of `DOCKER_CONFIG` is used as the path. `DOCKER_CONFIG` can be set to a directory (as per Docker CLI) or a file path directly. `config_file` has precedence over all other options.", Optional: true, }, "config_file_content": schema.StringAttribute{ diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 4de99b5f..c936c039 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -8,6 +8,7 @@ import ( "log" "os" "os/user" + "path/filepath" "runtime" "strings" "sync" @@ -128,12 +129,23 @@ func New(version string) func() *schema.Provider { }, "config_file": { - Type: schema.TypeString, - Optional: true, - DefaultFunc: schema.EnvDefaultFunc("DOCKER_CONFIG", "~/.docker/config.json"), - Description: "Path to docker json file for registry auth. Defaults to `~/.docker/config.json`. If `DOCKER_CONFIG` is set, the value of `DOCKER_CONFIG` is used as the path. `config_file` has predencen over all other options.", + Type: schema.TypeString, + Optional: true, + DefaultFunc: func() (interface{}, error) { + if v := os.Getenv("DOCKER_CONFIG"); v != "" { + // Docker CLI expects DOCKER_CONFIG to be a directory containing config.json + // Check if it's a directory and append config.json if needed + info, err := os.Stat(v) + if err == nil && info.IsDir() { + return filepath.Join(v, "config.json"), nil + } + // If it's a file or doesn't exist, use it as-is for backwards compatibility + return v, nil + } + return "~/.docker/config.json", nil + }, + Description: "Path to docker json file for registry auth. Defaults to `~/.docker/config.json`. If `DOCKER_CONFIG` env variable is set, the value of `DOCKER_CONFIG` is used as the path. `DOCKER_CONFIG` can be set to a directory (as per Docker CLI) or a file path directly. `config_file` has precedence over all other options.", }, - "config_file_content": { Type: schema.TypeString, Optional: true,