Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Fix panic to migrate schema of docker_container from v1 to v2 #271

Merged
merged 3 commits into from
Aug 2, 2020
Merged

Fix panic to migrate schema of docker_container from v1 to v2 #271

merged 3 commits into from
Aug 2, 2020

Conversation

suzuki-shunsuke
Copy link
Contributor

@suzuki-shunsuke suzuki-shunsuke commented Jun 7, 2020

Closes #264

=> #264 (comment)

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.

@ghost ghost added the size/XS label Jun 7, 2020
@suzuki-shunsuke suzuki-shunsuke changed the title Fix panic to migrate schema from v0 to v1 Fix panic to migrate schema from v1 to v2 Jun 7, 2020
@suzuki-shunsuke suzuki-shunsuke changed the title Fix panic to migrate schema from v1 to v2 Fix panic to migrate schema of docker_container from v1 to v2 Jun 7, 2020
@suzuki-shunsuke
Copy link
Contributor Author

suzuki-shunsuke commented Jun 7, 2020

The panic is solved, but I found the other problem.
The container is recreated due to the change of env.

#264 (comment)

$ terraform apply
$ vi main.tf # upgrade docker provider from 2.6.0 to 2.7.0 or 2.7.1
$ terraform init
$ terraform plan
      ...
      env.#:            "" => <computed> (forces new resource)
      ...
$ 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_image.nginx: Refreshing state... (ID: sha256:4392e5dad77dbaf6a573650b0fe1e282b57c5fba6e6cea00a27
c7d4b68539b81nginx)
docker_container.iis_services: Refreshing state... (ID: de1e5024beba5f0c8dd4c1d4bfcc2e45ff23ad61441653f
5a0753120b3536f7f)

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

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

Terraform will perform the following actions:

-/+ docker_container.iis_services (new resource required)
      id:               "de1e5024beba5f0c8dd4c1d4bfcc2e45ff23ad61441653f5a0753120b3536f7f" => <computed
> (forces new resource)
      attach:           "false" => "false"
      bridge:           "" => <computed>
      command.#:        "3" => <computed>
      container_logs:   "" => <computed>
      entrypoint.#:     "1" => <computed>
      env.#:            "" => <computed> (forces new resource)
      exit_code:        "" => <computed>
      gateway:          "172.17.0.1" => <computed>
      hostname:         "de1e5024beba" => <computed>
      image:            "sha256:4392e5dad77dbaf6a573650b0fe1e282b57c5fba6e6cea00a27c7d4b68539b81" => "s
ha256:4392e5dad77dbaf6a573650b0fe1e282b57c5fba6e6cea00a27c7d4b68539b81"
      ip_address:       "172.17.0.2" => <computed>
      ip_prefix_length: "16" => <computed>
      ipc_mode:         "private" => <computed>
      labels.#:         "0" => <computed>
      log_driver:       "json-file" => <computed>
      log_opts.%:       "0" => <computed>
      logs:             "false" => "false"
      must_run:         "true" => "true"
      name:             "iis-services" => "iis-services"
      network_data.#:   "1" => <computed>
      read_only:        "false" => "false"
      restart:          "always" => "always"
      rm:               "false" => "false"
      shm_size:         "64" => <computed>
      start:            "true" => "true"
      user:             "" => <computed>


Plan: 1 to add, 0 to change, 1 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.

If we remove the Computed: true from env, this problem is solved.
But I don't know whether we should remove Computed: true from env or not.

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

@suzuki-shunsuke
Copy link
Contributor Author

suzuki-shunsuke commented Jun 7, 2020

In my understanding, by #269 we stop to import env to State so we can remove Computed: true from env.

@mavogel mavogel added this to the v2.7.2 milestone Aug 2, 2020
@mavogel mavogel self-requested a review August 2, 2020 16:21
Copy link
Contributor

@mavogel mavogel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the fix. I'll set up a call in the upcoming weeks with the hashicorp folks to determine the correct usage of all the attributes.

@mavogel mavogel merged commit 863fc4c into hashicorp:master Aug 2, 2020
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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