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

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

Closed suzuki-shunsuke closed 4 years ago

suzuki-shunsuke commented 4 years ago

Closes #264

=> https://github.com/terraform-providers/terraform-provider-docker/issues/264#issuecomment-640154237

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.

suzuki-shunsuke commented 4 years ago

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

https://github.com/terraform-providers/terraform-provider-docker/issues/264#issuecomment-640154237

$ 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" => (forces new resource) attach: "false" => "false" bridge: "" => command.#: "3" => container_logs: "" => entrypoint.#: "1" => env.#: "" => (forces new resource) exit_code: "" => gateway: "172.17.0.1" => hostname: "de1e5024beba" => image: "sha256:4392e5dad77dbaf6a573650b0fe1e282b57c5fba6e6cea00a27c7d4b68539b81" => "s ha256:4392e5dad77dbaf6a573650b0fe1e282b57c5fba6e6cea00a27c7d4b68539b81" ip_address: "172.17.0.2" => ip_prefix_length: "16" => ipc_mode: "private" => labels.#: "0" => log_driver: "json-file" => log_opts.%: "0" => logs: "false" => "false" must_run: "true" => "true" name: "iis-services" => "iis-services" network_data.#: "1" => read_only: "false" => "false" restart: "always" => "always" rm: "false" => "false" shm_size: "64" => start: "true" => "true" user: "" => 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 commented 4 years ago

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