terraform-provider-docker
terraform-provider-docker copied to clipboard
Plan fails because docker_tag is dependent on local image
We are trying to copy images from our helm charts to our local repository so we do not have dependencies on external sources. We run our terraform from a pipeline and can't guarantee that the VM will have previously pulled images. This works the first time but a plan will fail if the local image referenced in state is not present.
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
Terraform (and docker Provider) Version
- Using Terraform v1.2.7
- Using kreuzwerker/docker v2.20.2
Affected Resource(s)
-
docker_tag
Terraform Configuration Files
# Data
data "azurerm_container_registry" "acr" {
name = var.registry_name
resource_group_name = var.registry_resource_group
}
# Resources
resource "docker_image" "grafana" {
name = "grafana/grafana:9.0.5"
triggers = {
every_time = "${timestamp()}"
}
}
resource "docker_tag" "grafana" {
source_image = docker_image.grafana.name
target_image = "${data.azurerm_container_registry.acr.login_server}/grafana:9.0.5"
# Added to see if it would change behavior
lifecycle {
replace_triggered_by = [docker_image.grafana]
}
}
resource "docker_registry_image" "grafana" {
name = "${data.azurerm_container_registry.acr.login_server}/grafana:9.0.5"
keep_remotely = true
depends_on = [docker_tag.grafana]
}
Debug Output
│ Error: failed to ImageInspectWithRaw: Error: No such image: grafana/grafana:9.0.5
│
│ with module.aks_config.docker_tag.grafana,
│ on modules/aks_config/images.tf line 18, in resource "docker_tag" "grafana":
│ 18: resource "docker_tag" "grafana" {
Panic Output
Expected Behaviour
The resource will recognize that a dependency is changing and not look for the local image during a plan.
Actual Behaviour
The plan will fail even after explicitly tainting the resource. The only thing that will work is to remove the state.
Steps to Reproduce
-
terraform apply
-
docker image rmi grafana/grafana:9.0.5 registry.azurecr.io/grafana:9.0.5
-
terraform plan
Important Factoids
References
- #0000