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
130 stars 92 forks source link

Docker service import crash - unexpected eof #258

Open brandonbumgarner opened 4 years ago

brandonbumgarner commented 4 years ago

Terraform version

0.11.14

Affected Resource(s)

Terraform Configuration Files

terraform {
  backend "s3" {
    bucket                      = "bucket"
    region                      = "region"
    profile                     = "profile"
    shared_credentials_file     = "credentials"
  }
}

provider "docker" {
  version = "~> 2.7.0"
  host                          = "tcp://${var.environment}.${var.domain}:9999/"
}

variable "domain" {
  default           = "domain"
}

variable "environment" {}

resource "docker_service" "service" {}

Panic Output

https://gist.github.com/brandonbumgarner/163a3145f7d1613a4d55dadc5dd0d0f2

Expected Behavior

The service should be imported into a state file stored in S3.

Actual Behavior

Terraform crashes. It seems like the state is captured, but when the state is refreshed, it crashes. The crash.log shows the docker inspect command output(stripped from gist, but in the actual it is there). So it seems that it is communicating with the docker node and getting the data.

Please keep in mind I have stripped the service id and any "sensitive" information from the logs and output. In the actual logs and output it has the specific environment, domain, service id, etc. For example: service-id is actually the id of a service that exists in that environment

terraform import -var "environment=env" docker_service.service service-id
docker_service.service: Importing from ID "service-id"...
docker_service.service: Import complete!
  Imported docker_service (ID: service-id)
docker_service.service: Refreshing state... (ID: service-id)

Error: docker_service.service (import id: service-id): 1 error occurred:
    * import docker_service.service result: service-id: docker_service.service: unexpected EOF

Steps to Reproduce

terraform init -var "environment=env" -backend-config="key=folder/service.state" terraform import -var "environment=env" docker_service.service service-id

Important Factoids

Right now I have the Docker provider pinned to 2.7.0, but have also tried 2.6.0. This had been working for most of our other services, but stopped working last week without any changes to the tf file.

mavogel commented 4 years ago

Hmm, strange, so it did not work with 2.6.0 either?

brandonbumgarner commented 4 years ago

That is correct. It had been working up until about 3 weeks ago with no changes to the files I had been using for the service imports. Now, it crashes consistently no matter what service I try to import.

Novex commented 4 years ago

I just tried upgrading to 2.7.0 and hit the same error as well on state refresh during a terraform apply

 Error: Error refreshing state: 1 error occurred:
    * docker_container.iis_services: 1 error occurred:
    * docker_container.iis_services: docker_container.iis_services: unexpected EOF

Terraform 0.11.14 as well, though I moved back a version to 2.6.0 and that is working for me.

We're connecting to docker on Windows Server 2016 as well if that helps, the server version is pretty old.

Server Version: 1.12.2-cs2-ws-beta
Default Isolation: process
Kernel Version: 10.0 14393 (14393.3630.amd64fre.rs1_release.200407-1730)
Operating System: Windows Server 2016 Datacenter
OSType: windows
sujith-apivista commented 4 years ago

In the following line, I believe Go will throw a panic if either of those values have not been initialized.

if string(service.Endpoint.Spec.Mode) == "" && string(service.Spec.EndpointSpec.Mode) == "" {

Could that be the issue?

brandonbumgarner commented 4 years ago

@Novex I tried to roll back to 2.6.0 and that did not work for me. This was actually one of the first things that I had tried, but thanks for providing this info.

@sujith-apivista Thanks for pointing this out! It seems that none of the services I had left to import had endpoints specified. After adding the endpoint spec mode to the service json, it imported successfully. I would suggest that a fix be implemented in the provider to handle a condition where endpoint spec might not be specified since it is not required by Docker. Thanks for your comments everyone!

  "EndpointSpec": {
    "Mode": "vip"
  }
Novex commented 4 years ago

I could have hit a different issue - is there any way to see the actual panic error thrown by the provider?

brandonbumgarner commented 4 years ago

@Novex I provided the crash log which has the panic error shown. Are you looking for that or something different?

Novex commented 4 years ago

Thanks for clarifying - I didn't realise the 'unexpected eof' was a generic something's wrong error. The error I found in my log file is different to yours so I've definitely got a different problem