kreuzwerker / terraform-provider-docker

Terraform Docker provider
Mozilla Public License 2.0
570 stars 187 forks source link

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

Open armona opened 1 month ago

armona commented 1 month ago

Community Note

Terraform (and docker Provider) Version

OpenTofu v1.7.1 on darwin_arm64

Affected Resource(s)

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