@@ -48,6 +48,12 @@ variable "protected_tags" {
4848 default = []
4949}
5050
51+ variable "protected_tags_keep_count" {
52+ type = number
53+ description = " Number of Image versions to keep for protected tags"
54+ default = 999999
55+ }
56+
5157variable "enable_lifecycle_policy" {
5258 type = bool
5359 description = " Enable/disable image lifecycle policy"
@@ -83,4 +89,85 @@ variable "replication_configurations" {
8389 }))
8490 description = " Replication configuration for a registry. See [Replication Configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecr_replication_configuration#replication-configuration)."
8591 default = []
86- }
92+ }
93+
94+ variable "custom_lifecycle_rules" {
95+ description = " Custom lifecycle rules to override or complement the default ones"
96+ type = list (object ({
97+ description = optional (string )
98+ selection = object ({
99+ tagStatus = string
100+ countType = string
101+ countNumber = number
102+ countUnit = optional (string )
103+ tagPrefixList = optional (list (string ))
104+ tagPatternList = optional (list (string ))
105+ })
106+ action = object ({
107+ type = string
108+ })
109+ }))
110+ default = []
111+
112+ validation {
113+ condition = alltrue ([
114+ for rule in var . custom_lifecycle_rules :
115+ rule . selection . tagStatus != " tagged" || (length (coalesce (rule. selection . tagPrefixList , [])) > 0 || length (coalesce (rule. selection . tagPatternList , [])) > 0 )
116+ ])
117+ error_message = " if tagStatus is tagged - specify tagPrefixList or tagPatternList"
118+ }
119+ validation {
120+ condition = alltrue ([
121+ for rule in var . custom_lifecycle_rules :
122+ rule . selection . countNumber > 0
123+ ])
124+ error_message = " Count number should be > 0"
125+ }
126+
127+ validation {
128+ condition = alltrue ([
129+ for rule in var . custom_lifecycle_rules :
130+ contains ([" tagged" , " untagged" , " any" ], rule. selection . tagStatus )
131+ ])
132+ error_message = " Valid values for tagStatus are: tagged, untagged, or any."
133+ }
134+ validation {
135+ condition = alltrue ([
136+ for rule in var . custom_lifecycle_rules :
137+ contains ([" imageCountMoreThan" , " sinceImagePushed" ], rule. selection . countType )
138+ ])
139+ error_message = " Valid values for countType are: imageCountMoreThan or sinceImagePushed."
140+ }
141+
142+ validation {
143+ condition = alltrue ([
144+ for rule in var . custom_lifecycle_rules :
145+ rule . selection . countType != " sinceImagePushed" || rule . selection . countUnit != null
146+ ])
147+ error_message = " For countType = 'sinceImagePushed', countUnit must be specified."
148+ }
149+ }
150+
151+ variable "default_lifecycle_rules_settings" {
152+ description = " Default lifecycle rules settings"
153+ type = object ({
154+ untagged_image_rule = optional (object ({
155+ enabled = optional (bool , true )
156+ }), {
157+ enabled = true
158+ })
159+ remove_old_image_rule = optional (object ({
160+ enabled = optional (bool , true )
161+ }), {
162+ enabled = true
163+ })
164+ })
165+ default = {
166+ untagged_image_rule = {
167+ enabled = true
168+ }
169+ remove_old_image_rule = {
170+ enabled = true
171+ }
172+ }
173+ }
0 commit comments