Creates an ECR lifecycle policy document to manage the lifecycle of images in an ECR repository based on tags and count conditions.

Terraform Template

data "aws_ecr_lifecycle_policy_document" "example" {

  rule {
    description = "This is a test."
    priority = 1

    selection {
      count_number = 100
      count_type = "imageCountMoreThan"
      tag_prefix_list = ["prod"]
      tag_status = "tagged"
    }
  }
}

resource "aws_ecr_lifecycle_policy" "example" {
  policy = data.aws_ecr_lifecycle_policy_document.example.json
  repository = "aws_ecr_repository.example.name"
}