modules/accelerator/ecs/ecr.tf (74 lines of code) (raw):

resource "aws_ecr_repository" "ecr-repo" { name = "${var.repo_name}-${var.region_name}" image_tag_mutability = "MUTABLE" image_scanning_configuration { scan_on_push = true } force_delete = true } resource "aws_ecr_repository_policy" "ecr_repository_policy" { repository = aws_ecr_repository.ecr-repo.name policy = <<EOF { "Version": "2008-10-17", "Statement": [ { "Sid": "new policy", "Effect": "Allow", "Principal": "*", "Action": [ "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 } resource "aws_ecr_lifecycle_policy" "ecr_image_policies" { repository = aws_ecr_repository.ecr-repo.name policy = <<EOF { "rules": [ { "rulePriority": 1, "description": "Expire images older than 14 days", "selection": { "tagStatus": "untagged", "countType": "sinceImagePushed", "countUnit": "days", "countNumber": 14 }, "action": { "type": "expire" } }, { "rulePriority": 2, "description": "Keep last 10 images", "selection": { "tagStatus": "tagged", "tagPrefixList": ["v"], "countType": "imageCountMoreThan", "countNumber": 10 }, "action": { "type": "expire" } } ] } EOF }