GithubHelp home page GithubHelp logo

Comments (5)

cosmotek avatar cosmotek commented on July 26, 2024 2

Here's an example I got working:

locals {
  docker_image_name = "my_docker_image"
}

resource "aws_ecr_repository" "ecr_repo" {
  name                 = local.docker_image_name
  image_tag_mutability = "IMMUTABLE"

  image_scanning_configuration {
    scan_on_push = true
  }
}

resource "aws_ecr_repository_policy" "ecr_repo_policy" {
  repository = aws_ecr_repository.ecr_repo.name

  policy = <<EOF
{
    "Version": "2008-10-17",
    "Statement": [
        {
            "Sid": "new policy",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "ecr:GetAuthorizationToken",
                "ecr:GetDownloadUrlForLayer",
                "ecr:BatchGetImage",
                "ecr:BatchCheckLayerAvailability",
                "ecr:PutImage",
                "ecr:InitiateLayerUpload",
                "ecr:UploadLayerPart",
                "ecr:CompleteLayerUpload",
                "ecr:DescribeRepositories",
                "ecr:GetRepositoryPolicy",
                "ecr:ListImages",
                "ecr:DeleteRepository",
                "ecr:BatchDeleteImage",
                "ecr:SetRepositoryPolicy",
                "ecr:DeleteRepositoryPolicy"
            ]
        }
    ]
}
EOF
}

provider "docker" {
  registry_auth {
    address     = data.aws_ecr_authorization_token.container_registry_token.proxy_endpoint
    username = data.aws_ecr_authorization_token.container_registry_token.user_name
    password = data.aws_ecr_authorization_token.container_registry_token.password
  }
}

data "aws_ecr_authorization_token" "container_registry_token" {}
resource "time_static" "now" {}

resource "docker_registry_image" "my_docker_image" {
  name = "${aws_ecr_repository.ecr_repo.repository_url}:build-${time_static.now.unix}"

  build {
    context = "${path.module}/src"
    labels = {
      dir_sha1 = sha1(join("", [for f in fileset("${path.module}/src", "*") : filesha1("${path.module}/src/${f}")]))
    }
  }
}

from terraform-provider-docker.

suzuki-shunsuke avatar suzuki-shunsuke commented on July 26, 2024

This may have nothing to do with the error, but your configuration file is wrong.

https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs#config_file_content

Cannot be used with the username/password or config_file options.

from terraform-provider-docker.

suzuki-shunsuke avatar suzuki-shunsuke commented on July 26, 2024

I could reproduce the error.

resource "docker_registry_image" "helloworld" {
  name = "something-amazing/helloworld:2.0"

  build {
    context = "context"
  }
}

data "aws_ecr_authorization_token" "token" {
}

provider "docker" {
  registry_auth {
    address  = "<aws account id>.dkr.ecr.ap-northeast-1.amazonaws.com"
    username = data.aws_ecr_authorization_token.token.user_name
    password = data.aws_ecr_authorization_token.token.password
  }
}

provider "aws" {
  region = "ap-northeast-1"
}
$ terraform version
Terraform v0.13.5
+ provider registry.terraform.io/hashicorp/aws v3.19.0
+ provider registry.terraform.io/kreuzwerker/docker v2.8.0
$ terraform apply
data.aws_ecr_authorization_token.token: Refreshing state...

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # docker_registry_image.helloworld will be created
  + resource "docker_registry_image" "helloworld" {
      + id            = (known after apply)
      + keep_remotely = false
      + name          = "something-amazing/helloworld:2.0"
      + sha256_digest = (known after apply)

      + build {
          + context    = "context:a1094ea0c6474f9d4eee107593ef19211a9009797363cd598a44daaf8abc75de"
          + dockerfile = "Dockerfile"
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

docker_registry_image.helloworld: Creating...

Error: Error pushing docker image: Error response from daemon: Bad parameters and missing X-Registry-Auth: EOF

  on main.tf line 1, in resource "docker_registry_image" "helloworld":
   1: resource "docker_registry_image" "helloworld" {

from terraform-provider-docker.

suzuki-shunsuke avatar suzuki-shunsuke commented on July 26, 2024

@antonbabenko

It succeeded to push a Docker image by adding the registry path to docker_registry_image's name.

resource "docker_registry_image" "helloworld" {
  # name = "something-amazing/helloworld:2.0"
  name = "<aws account id>.dkr.ecr.ap-northeast-1.amazonaws.com/something-amazing/helloworld:2.0"

  build {
    context = "context"
  }
}

from terraform-provider-docker.

antonbabenko avatar antonbabenko commented on July 26, 2024

Thank you, this works as expected.

I have just updated the Terraform AWS Lambda module and reference to this provider - https://github.com/terraform-aws-modules/terraform-aws-lambda/pull/80/files#diff-b71ad04f644acd7192bbc30fcb3f747a785983233f38a333c93c9f4541f7989a

from terraform-provider-docker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.