Skip to content

Commit

Permalink
feat: ecr lifecycle policies (#1)
Browse files Browse the repository at this point in the history
* feat(ecr): added lifecycle policies for the repository

* improvement(ecr): adjusted number of saved images
  • Loading branch information
Eik Emil Christensen authored Aug 13, 2020
1 parent ce77ac5 commit 07c8901
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions src/aws/ecr/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ resource "aws_ecr_repository" "repository" {
image_scanning_configuration {
scan_on_push = true
}
tags = var.common_tags
tags = var.common_tags
}

resource "aws_ecr_repository_policy" "policy" {
repository = aws_ecr_repository.repository.name
policy = <<EOF
policy = <<EOF
{
"Statement": [
{
Expand All @@ -31,4 +31,51 @@ resource "aws_ecr_repository_policy" "policy" {
"Version": "2008-10-17"
}
EOF
}

resource "aws_ecr_lifecycle_policy" "this" {
policy = jsonencode({
rules = [
{
rulePriority = 1
description = "keep the last 5 production images"
selection = {
tagStatus = "tagged"
tagPrefixList = ["v"]
countType = "imageCountMoreThan"
countNumber = 5
}
action = {
type = "expire"
}
},
{
rulePriority = 5
description = "keep the last 5 stable images"
selection = {
tagStatus = "tagged"
tagPrefixList = ["stable-"]
countType = "imageCountMoreThan"
countNumber = 5
}
action = {
type = "expire"
}
},
{
rulePriority = 100
description = "other images"
selection = {
tagStatus = "any"
countType = "imageCountMoreThan"
countNumber = 15
}
action = {
type = "expire"
}
},
]
})

repository = aws_ecr_repository.repository.name
}

0 comments on commit 07c8901

Please sign in to comment.