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

Container is not stopped when using `rm=true` #163

Open inercia opened 5 years ago

inercia commented 5 years ago

Terraform Version

Terraform v0.11.15-dev

Affected Resource(s)

Terraform Configuration Files

provider "docker" {
  host = "tcp://127.0.0.1:2375/"
}

resource "docker_network" "network" {
  name            = "haproxy-test-net"
  check_duplicate = "true"
}

resource "docker_container" "haproxy-test" {
  name                  = "haproxy-test"
  image                 = "haproxy"
  start                 = true
  rm                    = true
  privileged            = true
  must_run              = true
  restart               = "no"
  destroy_grace_seconds = 60
  network_mode          = "bridge"

  upload {
    file    = "/usr/local/etc/haproxy/haproxy.cfg"
    content = <<EOF
    defaults
      timeout connect 10s
      timeout client 86400s
      timeout server 86400s

    frontend apiserver
      bind :6443
      default_backend apiserver-backend

    backend apiserver-backend
      option httpchk GET /healthz
      server localhost 127.0.0.1:6443 check check-ssl verify none
EOF

  }
}

Debug Output

cluster creation cluster destruction

Expected Behavior

The docker container should have been properly stopped, but it is still running after terraform destroy. A docker ps shows the container running.

Actual Behavior

From the docs "If true, then the container will be automatically removed after his execution. Terraform won't check this container after creation.", so it seems to be equivalent to the --rm flag of docker. However, the docker container is not stopped at all (let alone to be removed). Maybe the rm argument is not preoperly explained in the docs.

Looking at the code, it seems the only thing the provider does when destroying the container with rm=true is to remove the ID.

Steps to Reproduce

  1. Use rm=true in a container.
  2. terraform apply
  3. terraform destroy
andrewbulin commented 4 years ago

Reproduced Terraform v0.13.0 :

Was there some intention or reason having rm=true flag being set to result in setting an empty string on the ID, and returning nil, without stopping the container? Ref: https://github.com/terraform-providers/terraform-provider-docker/blob/master/docker/resource_docker_container_funcs.go#L750

suzuki-shunsuke commented 4 years ago

This option seems to be introduced by #43 and #106 . I guess originally this option was introduced for the short-lived container, which runs a command and is destoyed everytime terraform apply is run.

I think the description of this option is insufficient.

https://www.terraform.io/docs/providers/docker/r/container.html#rm

rm - (Optional, bool) If true, then the container will be automatically removed after his execution. Terraform won't check this container after creation.