ecr_repo.tf 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. resource "aws_ecr_repository" "this" {
  2. name = var.name
  3. tags = merge(var.standard_tags, var.tags)
  4. image_scanning_configuration {
  5. scan_on_push = true
  6. }
  7. }
  8. data "aws_iam_policy_document" "ecr_repository_policy" {
  9. statement {
  10. sid = "LetCodebuildServiceUseTheseImages"
  11. effect = "Allow"
  12. principals {
  13. type = "Service"
  14. identifiers = [ "codebuild.amazonaws.com" ]
  15. }
  16. actions = [
  17. "ecr:GetDownloadUrlForLayer",
  18. "ecr:BatchGetImage",
  19. "ecr:BatchCheckLayerAvailability"
  20. ]
  21. }
  22. statement {
  23. sid = "LetCodebuildIAMRolePushImagesHere"
  24. effect = "Allow"
  25. principals {
  26. type = "AWS"
  27. identifiers = [ var.codebuild_assume_role_arn ]
  28. }
  29. actions = [
  30. "ecr:BatchCheckLayerAvailability",
  31. "ecr:BatchGetImage",
  32. "ecr:CompleteLayerUpload",
  33. "ecr:DescribeImages",
  34. "ecr:DescribeRepositories",
  35. "ecr:GetAuthorizationToken",
  36. "ecr:GetDownloadUrlForLayer",
  37. "ecr:InitiateLayerUpload",
  38. "ecr:ListImages",
  39. "ecr:PutImage",
  40. "ecr:UploadLayerPart",
  41. ]
  42. }
  43. }
  44. #Allow codebuild to access the ECR Repository to use the images
  45. resource "aws_ecr_repository_policy" "this" {
  46. repository = aws_ecr_repository.this.name
  47. policy = data.aws_iam_policy_document.ecr_repository_policy.json
  48. }