Open ssigwart opened 6 months ago
I'd be willing to attempt to fix this if a maintainer confirmed that what I have listed as the "Expected Behaviour" above is the desired behavior.
To add, I think deleting the container in a "plan" stage (which is not supposed to make any changes) creates quite some problems. E.g. I encountered this issue while not noticing that the container had crashed and by deleting the container docker also cleans up the logs, which prevents me from debugging the issue and I should have been warned before that was attempted.
Community Note
Terraform (and docker Provider) Version
Affected Resource(s)
docker_container
Terraform Configuration Files
Debug Output
Here are relevant snippets
Expected Behaviour
If a container is stopped and you run
docker plan
ordocker apply
without confirming, the docker container should remain unchanged. If the plan is applied, the existing container should be started if there are no other changes or replaced if there are config changes that require replacing it.Actual Behaviour
The stopped container is destroyed.
Steps to Reproduce
terraform apply
terraform plan
orterraform apply
. You'll notice in docker that the container is destroyed.References
Based on the debug logs, these blocks of code look relevant.
The code noticed that the container is not running here: https://github.com/kreuzwerker/terraform-provider-docker/blob/54685a5fb9b375961620d2c555c7f3925327112c/internal/provider/resource_docker_container_funcs.go#L790-L791
That then triggers the container to be deleted here: https://github.com/kreuzwerker/terraform-provider-docker/blob/54685a5fb9b375961620d2c555c7f3925327112c/internal/provider/resource_docker_container_funcs.go#L617-L619
If I add
must_run = false
to the container, the following line triggers and prevents it from deleting the container. However, it also does not restart the container when I runterraform apply
, so I don't think that's the solution to this issue. https://github.com/kreuzwerker/terraform-provider-docker/blob/54685a5fb9b375961620d2c555c7f3925327112c/internal/provider/resource_docker_container_funcs.go#L783-L788