fix: Use DOCKER_CONFIG env same way as with docker cli (#849)
Some checks are pending
Acc Tests / acc-test (TestAccDockerConfig, 1.8.x) (push) Waiting to run
Acc Tests / acc-test (TestAccDockerNetwork, 1.8.x) (push) Waiting to run
Acc Tests / acc-test (TestAccDockerPlugin, 1.8.x) (push) Waiting to run
Acc Tests / acc-test (TestAccDockerSecret, 1.8.x) (push) Waiting to run
Acc Tests / acc-test (TestAccDockerTag, 1.8.x) (push) Waiting to run
Acc Tests / acc-test (TestAccDockerVolume, 1.8.x) (push) Waiting to run
Acc Tests / acc-test (true, TestAccDockerContainer, 1.8.x) (push) Waiting to run
Acc Tests / acc-test (true, TestAccDockerImage, 1.8.x) (push) Waiting to run
Acc Tests / acc-test (true, TestAccDockerRegistryImage, 1.8.x) (push) Waiting to run
Acc Tests / acc-test (true, TestAccDockerService, 1.8.x) (push) Waiting to run
Compile Binaries / compile-fast (push) Waiting to run
Compile Binaries / compile (push) Waiting to run
golangci-lint / lint (push) Waiting to run
Unit Tests / unit-test (push) Waiting to run
Website Checks / markdown-link-check (push) Waiting to run
Docs and Website Lint / website-generation (push) Waiting to run
Docs and Website Lint / website-lint-spellcheck-tffmt (push) Waiting to run
Docs and Website Lint / markdown-lint (push) Waiting to run

This commit is contained in:
Martin 2026-02-03 22:51:20 +01:00 committed by GitHub
parent 30deab239b
commit a04f0ff82a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 8 deletions

View file

@ -25,7 +25,6 @@ jobs:
fail-fast: false
matrix:
terraform_version:
- "0.15.x"
- "1.8.x"
resource_type:
- "TestAccDockerConfig"

View file

@ -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.

View file

@ -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{

View file

@ -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,