Creates an AWS Elastic Container Registry Public repository and applies a custom access policy to it.

Terraform Template

data "aws_iam_policy_document" "example" {

  statement {
    actions = ["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"]
    effect = "Allow"

    principals {
      identifiers = ["123456789012"]
      type = "AWS"
    }
    sid = "new policy"
  }
}

resource "aws_ecrpublic_repository" "example" {
  repository_name = "example"
}

resource "aws_ecrpublic_repository_policy" "example" {
  policy = data.aws_iam_policy_document.example.json
  repository_name = aws_ecrpublic_repository.example.repository_name
}