Skip to content

Commit aaa22e7

Browse files
authored
Update Submodule and support custom_lifcycle_rules (#44)
* update submodule and vars * update module * add additional pass through variable * update module again * Adding an input description.
1 parent cf1d674 commit aaa22e7

File tree

2 files changed

+103
-12
lines changed

2 files changed

+103
-12
lines changed

src/main.tf

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,21 @@ module "ecr" {
2626
source = "cloudposse/ecr/aws"
2727
version = "0.44.0"
2828

29-
protected_tags = var.protected_tags
30-
enable_lifecycle_policy = var.enable_lifecycle_policy
31-
image_names = var.images
32-
image_tag_mutability = var.image_tag_mutability
33-
max_image_count = var.max_image_count
34-
principals_full_access = compact(concat(module.full_access.principals, [local.ecr_user_arn]))
35-
principals_readonly_access = module.readonly_access.principals
36-
principals_lambda = var.principals_lambda
37-
scan_images_on_push = var.scan_images_on_push
38-
use_fullname = false
39-
replication_configurations = var.replication_configurations
29+
protected_tags = var.protected_tags
30+
protected_tags_keep_count = var.protected_tags_keep_count
31+
enable_lifecycle_policy = var.enable_lifecycle_policy
32+
default_lifecycle_rules_settings = var.default_lifecycle_rules_settings
33+
image_names = var.images
34+
image_tag_mutability = var.image_tag_mutability
35+
max_image_count = var.max_image_count
36+
principals_full_access = compact(concat(module.full_access.principals, [local.ecr_user_arn]))
37+
principals_readonly_access = module.readonly_access.principals
38+
principals_lambda = var.principals_lambda
39+
scan_images_on_push = var.scan_images_on_push
40+
use_fullname = false
41+
replication_configurations = var.replication_configurations
42+
43+
custom_lifecycle_rules = var.custom_lifecycle_rules
4044

4145
context = module.this.context
4246
}

src/variables.tf

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
5157
variable "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

Comments
 (0)