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

panic: interface conversion: interface {} is nil, not []interface {} in docker.migrateContainerLabels #264

Closed Novex closed 4 years ago

Novex commented 4 years ago

Terraform Version

0.11.14

Affected Resource(s)

Terraform Configuration Files

resource "docker_container" "iis_services" {
  name  = "${local.name}-iis-services"
  image = "registry.gitlab.com/productname/productname:${var.channel}-iis-services"
  restart = "always"

  ports = {
      internal = 80
      external = "${var.odbc_port}"
  }

  env = [
      "PRODUCTNAME_SERVER=odbc-${local.name}.${module.shared.tld}",
      "PRODUCTNAME_PORT=${var.odbc_port}",
      "PRODUCTNAME_TLS=${var.odbc_tls ? "1" : ""}",

      "PRODUCTNAME_USERNAME=SYSTEMUSERNAME",
      "PRODUCTNAME_PASSWORD=${var.productname_system_password}"
  ]

  depends_on = ["docker_image.productname_iis_services"]
}

Debug Output

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

Panic Output

...
2020/04/27 03:56:58 [TRACE] dag/walk: added new vertex: "docker_container.iis_services"
2020/04/27 03:56:58 [TRACE] dag/walk: walking "docker_container.iis_services"
2020/04/27 03:56:58 [TRACE] vertex 'root.docker_container.iis_services': walking
2020/04/27 03:56:58 [TRACE] vertex 'root.docker_container.iis_services': evaluating
2020/04/27 03:56:58 [TRACE] [walkRefresh] Entering eval tree: docker_container.iis_services
2020/04/27 03:56:58 [TRACE] root: eval: *terraform.EvalSequence
2020/04/27 03:56:58 [TRACE] root: eval: *terraform.EvalGetProvider
2020/04/27 03:56:58 [TRACE] root: eval: *terraform.EvalReadState
2020/04/27 03:56:58 [TRACE] root: eval: *terraform.EvalRefresh
2020-04-27T03:56:58.694Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4: panic: interface conversion: interface {} is nil, not []interface {}
2020-04-27T03:56:58.507Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4: 
2020-04-27T03:56:58.507Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4: goroutine 113 [running]:
2020-04-27T03:56:58.507Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4: github.com/terraform-providers/terraform-provider-docker/docker.migrateContainerLabels(0xc0001ca1e0, 0xc0005a2118)
2020-04-27T03:56:58.507Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4:    /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-docker/docker/label_migration.go:18 +0x2d0
2020-04-27T03:56:58.507Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4: github.com/terraform-providers/terraform-provider-docker/docker.resourceDockerContainer.func1(0xc0001ca1e0, 0xf54200, 0xc0000bfb50, 0xc0001ca090, 0x13caf40, 0xc00000e858)
2020-04-27T03:56:58.507Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4:    /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-docker/docker/resource_docker_container.go:29 +0x2b
2020-04-27T03:56:58.507Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).upgradeState(0xc0003ff800, 0xc0003f9360, 0xf54200, 0xc0000bfb50, 0x1bab540, 0x0, 0x42f87c)
2020-04-27T03:56:58.507Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4:    /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-docker/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/resource.go:569 +0x2d0
2020-04-27T03:56:58.507Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).Refresh(0xc0003ff800, 0xc0003f9360, 0xf54200, 0xc0000bfb50, 0xc0000c3e98, 0x40be01, 0xc00024d4a0)
2020-04-27T03:56:58.507Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4:    /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-docker/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/resource.go:500 +0xcf
2020-04-27T03:56:58.507Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).Refresh(0xc00016b880, 0xc000524080, 0xc0003f9360, 0xc00024d4a0, 0xc0003f4780, 0x18)
2020-04-27T03:56:58.507Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4:    /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-docker/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/provider.go:328 +0x8f
2020-04-27T03:56:58.507Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4: github.com/hashicorp/terraform-plugin-sdk/plugin.(*ResourceProviderServer).Refresh(0xc0005846c0, 0xc000371c10, 0xc000371d00, 0x0, 0x0)
2020-04-27T03:56:58.507Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4:    /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-docker/vendor/github.com/hashicorp/terraform-plugin-sdk/plugin/resource_provider.go:552 +0x4e
2020-04-27T03:56:58.507Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4: reflect.Value.call(0xc00014a840, 0xc0000d45a0, 0x13, 0x116d115, 0x4, 0xc00020bf18, 0x3, 0x3, 0x40523a, 0xc0000bd020, ...)
2020-04-27T03:56:58.507Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4:    /opt/goenv/versions/1.13.1/src/reflect/value.go:460 +0x5f6
2020-04-27T03:56:58.508Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4: reflect.Value.Call(0xc00014a840, 0xc0000d45a0, 0x13, 0xc0004ee718, 0x3, 0x3, 0x64847b, 0xc00058ca80, 0x0)
2020-04-27T03:56:58.508Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4:    /opt/goenv/versions/1.13.1/src/reflect/value.go:321 +0xb4
2020-04-27T03:56:58.508Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4: net/rpc.(*service).call(0xc0002cf480, 0xc0000e83c0, 0xc0005a4520, 0xc0005a4530, 0xc00012c600, 0xc0000e2fe0, 0xf53480, 0xc000371c10, 0x16, 0xf534c0, ...)
2020-04-27T03:56:58.508Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4:    /opt/goenv/versions/1.13.1/src/net/rpc/server.go:377 +0x16f
2020-04-27T03:56:58.508Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4: created by net/rpc.(*Server).ServeCodec
2020-04-27T03:56:58.508Z [DEBUG] plugin.terraform-provider-docker_v2.7.0_x4:    /opt/goenv/versions/1.13.1/src/net/rpc/server.go:474 +0x42b
2020/04/27 03:56:58 [ERROR] root: eval: *terraform.EvalRefresh, err: docker_container.iis_services: unexpected EOF
2020/04/27 03:56:58 [ERROR] root: eval: *terraform.EvalSequence, err: docker_container.iis_services: unexpected EOF
2020/04/27 03:56:58 [TRACE] [walkRefresh] Exiting eval tree: docker_container.iis_services
2020/04/27 03:56:58 [TRACE] dag/walk: upstream errored, not walking "provider.docker (close)"
2020-04-27T03:56:58.511Z [DEBUG] plugin: plugin process exited: path=/root/.terraform.d/plugins/linux_amd64/terraform-provider-docker_v2.7.0_x4
...

Expected Behavior

terraform apply should have completed successfully

Actual Behavior

The provider crashed with an Unexpected EOF error

Steps to Reproduce

  1. terraform apply

Important Factoids

This works fine on v2.6.0, so it must have been something that changed for v2.7.0

We're connecting to docker on Windows Server 2016 - 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

I can reproduce this reliable and can provide more information/try things if needed.

suzuki-shunsuke commented 4 years ago

I can reproduce this issue.

Terraform v0.11.14

main.tf

provider "docker" {
  version = "2.6.0"
}

resource "docker_image" "nginx" {
  name = "nginx"
}

resource "docker_container" "iis_services" {
  name    = "iis-services"
  image   = "${docker_image.nginx.latest}"
  restart = "always"
}
$ terraform apply
# Confirm that "mounts" isn't set in terraform.tfstate
$ vi main.tf # upgrade docker provider from 2.6.0 to 2.7.0 or 2.7.1
$ terraform init
$ terraform plan # panic

If mounts isn't set in Terraform Configuration with Docker provider v2.6.0, mounts isn't set in State. So rawState doesn't have the key mounts and rawState["mounts"].([]interface{}) occurs panic.

https://github.com/terraform-providers/terraform-provider-docker/blob/v2.7.1/docker/label_migration.go#L18

mounts := rawState["mounts"].([]interface{})

panic: interface conversion: interface {} is nil, not []interface {}


I have created a pull request to fix this issue. https://github.com/terraform-providers/terraform-provider-docker/pull/271