terraform-provider-docker
terraform-provider-docker copied to clipboard
Support for docker_image.image_id
Community Note
- 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
Description
docker_image.latest
is deprecated, but this is the only property that returns the image ID. I agree that .latest
is confusing, not just here but also confusing in certain OCI registries where latest
is just a manually updated tag like tags in git, not an auto-computed value like HEAD
is in git.
The deprecation notice suggests you use repo_digest
instead, which does consistently result in the correct image deploying, but because when the state is refreshed the docker_container.image
is recomputed to be the image ID it results in recreating your containers on every terraform apply
. However, if this is set to the image ID of the image the container will correctly create itself only once.
I suggest that we rename docker_image.latest
to docker_image.image_id
(duplicating this functionality during a deprecation period). I'm comfortable adding this feature myself but would prefer indication that it would be accepted by maintainers first.
To add further possible confusion: there is already the docker_image.id
, which concatenates the docker image ID with the image repo+name, and this is used internally by terraform for resource identification so it probably has a good reason for being this way. Probably if the .id
didn't include this string, we would get strange behaviour if a user defined two docker images with different tags that happened to collide on the same value (imagine a trying to deploy two environments with a dev
tag and a stable
tag which are usually different but are the same after a major release)
New or Affected Resource(s)
- docker_image
- data.docker_image
Potential Terraform Configuration
data "docker_registry_image" "archivebox" {
name = "archivebox/archivebox:latest"
}
resource "docker_image" "archivebox" {
name = data.docker_registry_image.archivebox.name
pull_triggers = [data.docker_registry_image.archivebox.sha256_digest]
}
resource "docker_container" "archive" {
image = docker_image.archivebox.latest
name = "archive"
}
References
- n/a