Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when pushing ECR public registry: unable to get digest: Got bad response from registry: 400 Bad Request #622

Open
armona opened this issue May 28, 2024 · 2 comments · May be fixed by #666

Comments

@armona
Copy link

armona commented May 28, 2024

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

OpenTofu v1.7.1
on darwin_arm64

  • provider registry.opentofu.org/hashicorp/aws v5.51.1
  • provider registry.opentofu.org/kreuzwerker/docker v3.0.2

Affected Resource(s)

  • docker_registry_image

Terraform Configuration Files

terraform {
  required_version = ">= 1.2"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }

    docker = {
      source  = "kreuzwerker/docker"
      version = "~> 3.0"
    }
  }
}

variable "image_name" {
  type = string
}

variable "dockerfile" {
  type = string
  default = "Dockerfile"
}

provider "docker" {
  registry_auth {
    address  = "public.ecr.aws"
    username = data.aws_ecrpublic_authorization_token.token.user_name
    password = data.aws_ecrpublic_authorization_token.token.password
  }
}

data "aws_ecrpublic_authorization_token" "token" {}

resource "docker_image" "builder" {
  name = var.image_name

  build {
    dockerfile = var.dockerfile
    context    = path.module

    auth_config {
      host_name = "public.ecr.aws"
      auth      = data.aws_ecrpublic_authorization_token.token.authorization_token
    }
  }
}

resource "docker_registry_image" "this" {
  name          = docker_image.builder.name
  keep_remotely = true
}

Debug Output

Panic Output

Expected Behaviour

The image should be pushed to remote registry, and finish without error.

Actual Behaviour

The image was pushed successfully, but the terraform apply failed with the following error:

╷
│ Error: Unable to create image, image not found: unable to get digest: Got bad response from registry: 400 Bad Request
│
│   with docker_registry_image.default[0],
│   on main.tf line 113, in resource "docker_registry_image" "default":
│  113: resource "docker_registry_image" "default" {

Steps to Reproduce

  1. Create a public ECR registry
  2. terraform apply

Important Factoids

References

@jjfuentes02
Copy link

jjfuentes02 commented Aug 24, 2024

@armona I am also experiencing same issue. Any luck figuring this out? Otherwise, will have to handle the building and pushing to ECR without using Terraform :(.

Temp workaround for getting passed this issue:

resource "null_resource" "push_to_ecr" {
provisioner "local-exec" {
command = <<EOT
docker push ${var.ecr_repo_url}:latest
EOT
}

depends_on = [
docker_image.docker_image_name
]
}

@armona
Copy link
Author

armona commented Aug 24, 2024

@jjfuentes02 Unfortunately no, couldn't find a workaround using this provider.

@achille-roussel achille-roussel linked a pull request Jan 4, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants