lifecycle.tf 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Simple lifecycle policy that expires images that are untagged, or over 1 year old.
  2. #
  3. # Lifecycle policies for ECR aren't very powerful. To do better than this,
  4. # we would need to change the way we tag images. But ECR is nearly as cheap
  5. # as S3 storage, so a few extra images isn't going to hurt anybody.
  6. resource "aws_ecr_lifecycle_policy" "basicpolicy" {
  7. repository = aws_ecr_repository.this.name
  8. policy = <<EOF
  9. {
  10. "rules": [
  11. {
  12. "rulePriority": 1,
  13. "description": "Remove Untagged Images",
  14. "selection": {
  15. "tagStatus": "untagged",
  16. "countType": "sinceImagePushed",
  17. "countUnit": "days",
  18. "countNumber": 1
  19. },
  20. "action": {
  21. "type": "expire"
  22. }
  23. },
  24. {
  25. "rulePriority": 2,
  26. "description": "Remove images older than 1 year",
  27. "selection": {
  28. "tagStatus": "any",
  29. "countType": "sinceImagePushed",
  30. "countUnit": "days",
  31. "countNumber": 365
  32. },
  33. "action": {
  34. "type": "expire"
  35. }
  36. }
  37. ]
  38. }
  39. EOF
  40. }