terraform policy

This commit is contained in:
Jun-te Kim 2025-07-21 13:35:34 +00:00
parent 8fe3938116
commit 95aad5c78f
2 changed files with 27 additions and 14 deletions

View file

@ -30,20 +30,33 @@ resource "aws_ecr_lifecycle_policy" "extractor_loader_lifecycle" {
repository = aws_ecr_repository.extractor_and_loader.name
policy = jsonencode({
rules = [
{
rulePriority = 1
description = "Delete tagged images older than 14 days"
selection = {
tagStatus = "tagged"
countType = "sinceImagePushed"
countUnit = "days"
countNumber = 5
"rules": [
{
"rulePriority": 2,
"description": "Expire images older than 14 days",
"selection": {
"tagStatus": "untagged",
"countType": "sinceImagePushed",
"countUnit": "days",
"countNumber": 1
},
"action": {
"type": "expire"
}
},
{
"rulePriority": 1,
"description": "Keep last 5 images",
"selection": {
"tagStatus": "tagged",
"tagPrefixList": ["feature"],
"countType": "imageCountMoreThan",
"countNumber": 5
},
"action": {
"type": "expire"
}
}
action = {
type = "expire"
}
}
]
})
}

View file

@ -25,7 +25,7 @@ resource "aws_ecr_repository_policy" "lambda_example_ecr_access" {
}
# ECR lifecycle policy to delete tagged images older than 14 days
resource "aws_ecr_lifecycle_policy" "extractor_loader_lifecycle" {
resource "aws_ecr_lifecycle_policy" "lambda_example_ecr_lifecycle" {
repository = aws_ecr_repository.lambda_example.name
policy = jsonencode({