Skip to content

doingcloudright/terraform-aws-ecr-lifecycle-policy-rule

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS ECR Module Build Status

This module simplifies the creation of an ECR life cycle rule. And can be used in combination with doingcloudright/ecr-cross-account/aws. NB: Badly created ECR Lifecycle rules can cause great harm, it's important to review the created lifecycle rules.

Rules can be made for all available tag statuses [ tagged, untagged, any ], in combination with all count types [ imageCountMoreThan, sinceImagePushed ]. The default output has a rule_priority $${rule_priority} which can be interpreted by a data "template_file" in a different module. If needed the rule_priority can be overridden.

Examples

Rotate after 30 images exist for ["test","uat","prod"]

module "ecr_lifecycle_rule_tagged_image_count_30" {
  source = "doingcloudright/ecr-lifecycle-policy-rule/aws"

  tag_status = "tagged"
  count_type = "imageCountMoreThan"
  prefixes  = ["test","uat","prod"]
  count_number = 30
}

output "ecr_lifecycle_rule_tagged_image_count_30" {
  value = "${module.ecr_lifecycle_rule_tagged_image_count_30.policy_rule}"
}

Rotate images after 40 days since image pushed for ["test","uat","prod"]

module "ecr_lifecycle_rule_tagged_40_days_since_image_pushed" {
  source = "doingcloudright/ecr-lifecycle-policy-rule/aws"

  tag_status = "tagged"
  count_type = "sinceImagePushed"
  count_number = 40
  prefixes  = ["test","uat","prod"]
}

output "ecr_lifecycle_rule_tagged_40_days_since_image_pushed" {
  value = "${module.ecr_lifecycle_rule_tagged_40_days_since_image_pushed.policy_rule}"
}

Rotate images after 7 images exist for any

module "ecr_lifecycle_rule_any_7_images" {
  source = "doingcloudright/ecr-lifecycle-policy-rule/aws"

  tag_status = "any"
  count_type = "imageCountMoreThan"
  count_number = "7"
}

output "ecr_lifecycle_rule_any_7_images" {
  value = "${module.ecr_lifecycle_rule_any_7_images.policy_rule}"
}

Rotate images after 100 days since image pushed for untagged images

module "ecr_lifecycle_rule_untagged_100_days_since_image_pushed" {
  source = "doingcloudright/ecr-lifecycle-policy-rule/aws"

  tag_status = "untagged"
  count_type = "sinceImagePushed"
  count_number = "100"
}

output "ecr_lifecycle_rule_untagged_100_days_since_image_pushed" {
  value = "${module.ecr_lifecycle_rule_untagged_100_days_since_image_pushed.policy_rule}"
}

About

Terraform module which creates a JSON lifecycle policy rule for ECR

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages