Provides an ECR lifecycle policy.
resource "aws_ecr_repository" "foo" { name = "bar" } resource "aws_ecr_lifecycle_policy" "foopolicy" { repository = "${aws_ecr_repository.foo.name}" policy = <<EOF { "rules": [ { "rulePriority": 1, "description": "Expire images older than 14 days", "selection": { "tagStatus": "untagged", "countType": "sinceImagePushed", "countUnit": "days", "countNumber": 14 }, "action": { "type": "expire" } } ] } EOF }
resource "aws_ecr_repository" "foo" { name = "bar" } resource "aws_ecr_lifecycle_policy" "foopolicy" { repository = "${aws_ecr_repository.foo.name}" policy = <<EOF { "rules": [ { "rulePriority": 1, "description": "Keep last 30 images", "selection": { "tagStatus": "tagged", "tagPrefixList": ["v"], "countType": "imageCountMoreThan", "countNumber": 30 }, "action": { "type": "expire" } } ] } EOF }
The following arguments are supported:
repository
- (Required) Name of the repository to apply the policy. policy
- (Required) The policy document. This is a JSON formatted string. See more details about Policy Parameters in the official AWS docs. In addition to all arguments above, the following attributes are exported:
repository
- The name of the repository. registry_id
- The registry ID where the repository was created. ECR Lifecycle Policy can be imported using the name of the repository, e.g.
$ terraform import aws_ecr_lifecycle_policy.example tf-example
© 2018 HashiCorpLicensed under the MPL 2.0 License.
https://www.terraform.io/docs/providers/aws/r/ecr_lifecycle_policy.html