hashicorp / terraform-provider-docker

As part of our introduction to self-service publishing in the Terraform Registry, this copy of the provider has been archived, and ownership has been transferred to active maintainers in the community. Please see the new location on the Terraform Registry: https://registry.terraform.io/providers/kreuzwerker/docker/latest
https://registry.terraform.io/providers/kreuzwerker/docker/latest
Mozilla Public License 2.0
132 stars 91 forks source link

Adding an alias to a (lone) Docker provider pulls in default configuration. #244

Open dannmartens opened 4 years ago

dannmartens commented 4 years ago

Hi,

I could be working under a wrong assumption here, but the idea was to manage multiple remote Docker hosts, each with a matching alias. When all Docker providers in the configuration have an alias, the default Docker provider configuration gets evaluated as well, which will try to connect to a local Docker daemon over the unix domain socket. Docker is not installed on the Terraform host machine.

So, with just one Docker provider in the configuration, after adding an "alias," planning fails because the connection fails.

Workarounds:

Terraform Version

0.12.21

Terraform Configuration Files

provider "docker" {
  alias = "docker-remote-host"
  host = "ssh://user@${var.REMOTE-HOST}:22"
}

resource "docker_container" "REMOTE_HOST_API" {
  name  = "REMOTE_HOST_API"
...
}

Debug Output

Relevant part:

2020/02/25 11:52:34 [TRACE] buildProviderConfig for provider.docker: no configuration at all
2020/02/25 11:52:34 [TRACE] GRPCProvider: GetSchema
2020/02/25 11:52:35 [TRACE] GRPCProvider: Configure
2020/02/25 11:52:35 [ERROR] <root>: eval: *terraform.EvalConfigProvider, err: Error pinging Docker server: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
2020/02/25 11:52:35 [ERROR] <root>: eval: *terraform.EvalSequence, err: Error pinging Docker server: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
2020/02/25 11:52:35 [ERROR] <root>: eval: *terraform.EvalOpFilter, err: Error pinging Docker server: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
2020/02/25 11:52:35 [ERROR] <root>: eval: *terraform.EvalSequence, err: Error pinging Docker server: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Expected Behavior

I would have expected the same result, with or without an "alias" attribute present.

Actual Behavior

The "default" Docker provider is pulled into the evaluation, and as this one has no configuration, its host is set to the default: the local Docker daemon. The provider then proceeds by trying to connect to the local daemon, which fails because it isn't there.

Steps to Reproduce

Just add an alias to a Terraform configuration with a single Docker provider. Start a plan.