ecr_repo.tf 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. resource "aws_ecr_repository" "this" { # tfsec:ignore:aws-ecr-repository-customer-key tfsec:ignore:aws-ecr-enforce-immutable-repository
  2. # Risk is low for KMS AES-256 encryption
  3. name = var.name
  4. tags = merge(var.standard_tags, var.tags)
  5. # image_tag_mutability = "IMMUTABLE"
  6. # Allow mutable tags for now - TO-DO
  7. # MSOCI-2182 - This breaks the push process for new changes to the portal servers.
  8. # The codebuild code depends on being able to tag a new image with the latest tag.
  9. image_scanning_configuration {
  10. scan_on_push = true
  11. }
  12. }
  13. data "aws_iam_policy_document" "ecr_repository_policy" {
  14. statement {
  15. sid = "LetCodebuildServiceUseTheseImages"
  16. effect = "Allow"
  17. principals {
  18. type = "Service"
  19. identifiers = ["codebuild.amazonaws.com"]
  20. }
  21. actions = [
  22. "ecr:GetDownloadUrlForLayer",
  23. "ecr:BatchGetImage",
  24. "ecr:BatchCheckLayerAvailability"
  25. ]
  26. }
  27. statement {
  28. sid = "LetCodebuildIAMRolePushImagesHere"
  29. effect = "Allow"
  30. principals {
  31. type = "AWS"
  32. identifiers = [var.codebuild_assume_role_arn]
  33. }
  34. actions = [
  35. "ecr:BatchCheckLayerAvailability",
  36. "ecr:BatchGetImage",
  37. "ecr:CompleteLayerUpload",
  38. "ecr:DescribeImages",
  39. "ecr:DescribeRepositories",
  40. "ecr:GetAuthorizationToken",
  41. "ecr:GetDownloadUrlForLayer",
  42. "ecr:InitiateLayerUpload",
  43. "ecr:ListImages",
  44. "ecr:PutImage",
  45. "ecr:UploadLayerPart",
  46. ]
  47. }
  48. }
  49. #Allow codebuild to access the ECR Repository to use the images
  50. resource "aws_ecr_repository_policy" "this" {
  51. repository = aws_ecr_repository.this.name
  52. policy = data.aws_iam_policy_document.ecr_repository_policy.json
  53. }