terraform-provider-docker
terraform-provider-docker copied to clipboard
Conditionally rebuild image
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
Affected Resource(s)
docker_image
Terraform Configuration Files
locals {
docker = {
cli = {
version = var.INFRA_CLI_VERSION
rebuild_trigger = var.INFRA_CLI_REBUILD_TRIGGER
commit_sha = var.INFRA_CLI_COMMIT_SHA
}
# Other configs
}
}
# Previous version
resource "docker_registry_image" "images" {
for_each = local.docker
name = "${local.container_registry_url}/${local.resource_prefix}-${each.key}:v${each.value.version}-${each.value.commit_sha}"
keep_remotely = true
build {
context = "${path.root}/../dotnet"
dockerfile = "../docker/${each.key}.Dockerfile"
platform = "linux/arm64"
build_args = {
COMMIT_SHA = each.value.commit_sha
REBUILD_TRIGGER = each.value.rebuild_trigger
ASPNETCORE_ENVIRONMENT = var.ASPNETCORE_ENVIRONMENT
MYDOTNET_BUILD_CONFIGURATION = "Release"
HUSKY = 0
}
}
depends_on = [aws_ecr_repository.registries]
}
# Updated version
resource "docker_image" "images" {
for_each = local.docker
name = "${local.container_registry_url}/${local.resource_prefix}-${each.key}:v${each.value.version}-${each.value.commit_sha}"
keep_locally = true
build {
context = "${path.root}/../dotnet"
dockerfile = "../docker/${each.key}.Dockerfile"
platform = "linux/arm64"
build_args = {
COMMIT_SHA = each.value.commit_sha
REBUILD_TRIGGER = each.value.rebuild_trigger
ASPNETCORE_ENVIRONMENT = var.ASPNETCORE_ENVIRONMENT
MYDOTNET_BUILD_CONFIGURATION = "Release"
HUSKY = 0
}
}
depends_on = [aws_ecr_repository.registries]
}
Hi all,
mine isn't really a bug, it's more a behaviour change from version 2.25.0 to >= 3.0s.
I used to build docker images like in the posted code using docker_registry_image, by injecting different version, rebuild_trigger and commit_sha for each part of my application I could practically selectively decide from which image rebuild by changing those values.
Now that I upgraded the provider this trick sees to not be working anymore.
Is there a way to restore the previous behaviour?
Thank you.
Update
I tried now to use docker_registry_image but it still builds all the images:
resource "docker_registry_image" "image" {
for_each = local.docker
name = docker_image.images[each.key].name
keep_remotely = true
triggers = {
push_hash = sha256(jsonencode({
COMMIT_SHA = each.value.commit_sha
REBUILD_TRIGGER = each.value.rebuild_trigger
}))
}
}
resource "docker_image" "images" {
for_each = local.docker
name = "${local.container_registry_url}/${local.resource_prefix}-${each.key}:v${each.value.version}-${each.value.commit_sha}"
keep_locally = true
build {
context = "${path.root}/../dotnet"
dockerfile = "../docker/${each.key}.Dockerfile"
platform = "linux/arm64"
build_args = {
COMMIT_SHA = each.value.commit_sha
REBUILD_TRIGGER = each.value.rebuild_trigger
ASPNETCORE_ENVIRONMENT = var.ASPNETCORE_ENVIRONMENT
MYDOTNET_BUILD_CONFIGURATION = "Release"
HUSKY = 0
}
}
depends_on = [aws_ecr_repository.registries]
}
I checked the passed commit_sha and rebuild_trigger. Even changing them for just one part of the system, all the images are rebuilt.