LoginSignup
0
1

More than 1 year has passed since last update.

ECRのuntaggedイメージ削除

Last updated at Posted at 2021-01-07

備忘録です。
ご指摘等ありましたら教えていただけると幸いです。

最近現場で、新システムのインフラにECSの導入→コード化をしています。
latest運用にしており、untaggedイメージが増産されていました。
なのでサイクルを決めて削除するように変更しました。

下記コードは、
・ 1日のサイクルでuntaggedを削除
・ 1つだけイメージを残す

ecr.tf
# 作成済みECR
data "aws_ecr_repository" "app" {
  name = local.service_name
}

# untaggedイメージの削除
resource "aws_ecr_lifecycle_policy" "app" {
  repository = data.aws_ecr_repository.app.name

  policy = <<EOF
{
    "rules": [
        {
            "rulePriority": 1,
            "description": "Expire images older than 1 days",
            "selection": {
                "tagStatus": "untagged",
                "countType": "sinceImagePushed",
                "countUnit": "days",
                "countNumber": 1
            },
            "action": {
                "type": "expire"
            }
        }
    ]
}
EOF
}

参考文献

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecr_lifecycle_policy
https://docs.aws.amazon.com/ja_jp/AmazonECR/latest/userguide/lifecycle_policy_examples.html

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1