Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image value in docker_service state doesn't stick #50

Closed
mavogel opened this issue Dec 25, 2020 · 4 comments · Fixed by #212
Closed

Image value in docker_service state doesn't stick #50

mavogel opened this issue Dec 25, 2020 · 4 comments · Fixed by #212
Labels
bug Something isn't working r/service Relates to the service resource
Milestone

Comments

@mavogel
Copy link
Contributor

mavogel commented Dec 25, 2020

This issue was originally opened by @ragurakesh as hashicorp/terraform-provider-docker#291. It was migrated here as a result of the community provider takeover from @kreuzwerker. The original body of the issue is below.


Terraform Version

terraform:0.12.29
provider-docker version: 2.5.0

Affected Resource(s)

  • docker_service

Terraform Configuration Files

provider "docker" {
  version = "~> 2.5.0"
  alias   = "default"
}

resource "docker_service" "foo" {
  name = "foo-service"

  task_spec {
    container_spec {
      image = "nginx:latest"
    }
  }

  endpoint_spec {
    ports {
      target_port = "8080"
    }
  }
}

Apply Output

$ terraform apply

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # docker_service.foo will be created
  + resource "docker_service" "foo" {
      + id     = (known after apply)
      + labels = (known after apply)
      + name   = "foo-service"

      + endpoint_spec {
          + mode = (known after apply)

          + ports {
              + protocol     = "tcp"
              + publish_mode = "ingress"
              + target_port  = 8080
            }
        }

      + mode {
          + global = (known after apply)

          + replicated {
              + replicas = (known after apply)
            }
        }

      + task_spec {
          + force_update   = (known after apply)
          + restart_policy = (known after apply)
          + runtime        = (known after apply)

          + container_spec {
              + image             = "nginx:latest"
              + isolation         = "default"
              + stop_grace_period = (known after apply)

              + dns_config {
                  + nameservers = (known after apply)
                  + options     = (known after apply)
                  + search      = (known after apply)
                }

              + healthcheck {
                  + interval     = (known after apply)
                  + retries      = (known after apply)
                  + start_period = (known after apply)
                  + test         = (known after apply)
                  + timeout      = (known after apply)
                }
            }

          + placement {
              + constraints = (known after apply)
              + prefs       = (known after apply)

              + platforms {
                  + architecture = (known after apply)
                  + os           = (known after apply)
                }
            }

          + resources {
              + limits {
                  + memory_bytes = (known after apply)
                  + nano_cpus    = (known after apply)

                  + generic_resources {
                      + discrete_resources_spec = (known after apply)
                      + named_resources_spec    = (known after apply)
                    }
                }

              + reservation {
                  + memory_bytes = (known after apply)
                  + nano_cpus    = (known after apply)

                  + generic_resources {
                      + discrete_resources_spec = (known after apply)
                      + named_resources_spec    = (known after apply)
                    }
                }
            }
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

docker_service.foo: Creating...
docker_service.foo: Creation complete after 5s [id=dgyjey68z60ke8wploo9jpfme]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
$

Expected Behavior

Once the above configuration is applied, docker service shall run nginx container, and applying the same terraform configuration again shall not cause the running container to be recycled.

Actual Behavior

Plan shows change in the image configured in the docker_service. If applied again, it causes the running container to get recycled.

$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

docker_service.foo: Refreshing state... [id=dgyjey68z60ke8wploo9jpfme]

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # docker_service.foo will be updated in-place
  ~ resource "docker_service" "foo" {
        id     = "dgyjey68z60ke8wploo9jpfme"
        labels = {}
        name   = "foo-service"

        endpoint_spec {
            mode = "vip"

            ports {
                protocol       = "tcp"
                publish_mode   = "ingress"
                published_port = 0
                target_port    = 8080
            }
        }

        mode {
            global = false

            replicated {
                replicas = 1
            }
        }

      ~ task_spec {
            force_update   = 0
            networks       = []
            restart_policy = {
                "condition"    = "any"
                "max_attempts" = "0"
            }
            runtime        = "container"

          ~ container_spec {
                args              = []
                command           = []
                env               = {}
                groups            = []
               ~ image             = "nginx:latest@sha256:b0ad43f7ee5edbc0effbc14645ae7055e21bc1973aee5150745632a24a752661" -> "nginx:latest"
                isolation         = "default"
                labels            = {}
                read_only         = false
                stop_grace_period = "0s"

                dns_config {}

                healthcheck {
                    interval     = "0s"
                    retries      = 0
                    start_period = "0s"
                    test         = []
                    timeout      = "0s"
                }
            }

            placement {
                constraints = []
                prefs       = []

                platforms {
                    architecture = "amd64"
                    os           = "linux"
                }
            }

            resources {
            }
        }
    }

Plan: 0 to add, 1 to change, 0 to destroy.

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.
$

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                        PORTS               NAMES
07522dc88570        nginx:latest        "/docker-entrypoint.…"   23 seconds ago      Up 19 seconds                 80/tcp              foo-service.1.v7t3mqux9w3h4xdwft8hxpx9p
8e2cc03cf8e1        nginx:latest        "/docker-entrypoint.…"   9 minutes ago       Exited (137) 22 seconds ago                       foo-service.1.4humubt05iongzdxf5xvjsm79
$ 

Steps to Reproduce

  1. terraform apply above configuraion
  2. terraform apply again the same configuration
  3. docker ps -a
@mavogel mavogel added bug Something isn't working r/service Relates to the service resource labels Dec 25, 2020
@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity.
Remove stale label or comment or this will be closed in 7 days.
If you don't want this issue to be closed, please set the label pinned.

@github-actions github-actions bot added the stale label Mar 29, 2021
@bkk87
Copy link

bkk87 commented Mar 29, 2021

This issue is important because it blocks the usage of watchtower to update images.

@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity.
Remove stale label or comment or this will be closed in 7 days.
If you don't want this issue to be closed, please set the label pinned.

@github-actions github-actions bot added the stale label May 29, 2021
@mavogel mavogel removed the stale label May 30, 2021
@mavogel
Copy link
Contributor Author

mavogel commented May 30, 2021

related to #161. consistent image names in state

@mavogel mavogel modified the milestones: v3.0.0, v2.13.0 May 30, 2021
@mavogel mavogel linked a pull request Jun 1, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working r/service Relates to the service resource
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants