You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
If you are interested in working on this issue or have submitted a pull request, please leave a comment
Terraform (and docker Provider) Version
Terraform v1.4.6
on darwin_amd64
+ provider registry.terraform.io/kreuzwerker/docker v3.0.2
Affected Resource(s)
docker_container
Terraform Configuration Files
terraform {
required_providers {
docker = {
source ="kreuzwerker/docker"
version ="3.0.2"
}
}
}
data"docker_registry_image""redis" {
name ="redis:7-alpine"
}
resource"docker_image""redis" {
name ="redis:7-alpine"
keep_locally =true
pull_triggers = [data.docker_registry_image.redis.sha256_digest]
}
resource"docker_container""redis-container-2" {
image = docker_image.redis.image_id
name ="redis-2"
hostname ="redis-2"networks_advanced {
name ="my-network"
}
restart ="unless-stopped"
}
Debug Output
Here are relevant snippets
2023-12-16T13:05:37.433-0500 [INFO] provider.terraform-provider-docker_v3.0.2: 2023/12/16 13:05:37 [DEBUG] Container 4c1f15accff1abf8935dc508a3210c1859ea2930a4766668b490355383764b56 was not created: timestamp=2023-12-16T13:05:37.432-0500
2023-12-16T13:05:37.433-0500 [INFO] provider.terraform-provider-docker_v3.0.2: 2023/12/16 13:05:37 [INFO] Stopping Container '4c1f15accff1abf8935dc508a3210c1859ea2930a4766668b490355383764b56' with timeout 0s: timestamp=2023-12-16T13:05:37.432-0500
2023-12-16T13:05:37.451-0500 [WARN] Provider "registry.terraform.io/kreuzwerker/docker" produced an unexpected new value for docker_container.redis-container-2 during refresh.
- Root resource was present, but now absent
2023-12-16T13:05:37.462-0500 [INFO] provider.terraform-provider-docker_v3.0.2: 2023/12/16 13:05:37 [INFO] Removing Container '4c1f15accff1abf8935dc508a3210c1859ea2930a4766668b490355383764b56': timestamp=2023-12-16T13:05:37.436-0500
2023-12-16T13:05:37.463-0500 [INFO] provider.terraform-provider-docker_v3.0.2: 2023/12/16 13:05:37 [INFO] Waiting for Container '4c1f15accff1abf8935dc508a3210c1859ea2930a4766668b490355383764b56' with condition 'not-running': timestamp=2023-12-16T13:05:37.447-0500
2023-12-16T13:05:37.463-0500 [INFO] provider.terraform-provider-docker_v3.0.2: 2023/12/16 13:05:37 [INFO] Waiting for Container '4c1f15accff1abf8935dc508a3210c1859ea2930a4766668b490355383764b56' errord: 'Error response from daemon: No such container: 4c1f15accff1abf8935dc508a3210c1859ea2930a4766668b490355383764b56': timestamp=2023-12-16T13:05:37.451-0500
Expected Behaviour
If a container is stopped and you run docker plan or docker 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
Run terraform apply
Stop the container in docker.
Run terraform plan or terraform 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:
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 run terraform apply, so I don't think that's the solution to this issue.
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:
terraform-provider-docker/internal/provider/resource_docker_container_funcs.go
Lines 790 to 791 in 54685a5
That then triggers the container to be deleted here:
terraform-provider-docker/internal/provider/resource_docker_container_funcs.go
Lines 617 to 619 in 54685a5
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.terraform-provider-docker/internal/provider/resource_docker_container_funcs.go
Lines 783 to 788 in 54685a5
The text was updated successfully, but these errors were encountered: