Skip to content

Commit

Permalink
Align code for AWS ECR creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Khramtsov committed Aug 25, 2024
1 parent b55939e commit e0bf35a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
30 changes: 15 additions & 15 deletions terraform/modules/aws-ecr/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ resource "aws_ecr_repository" "this" {
scan_on_push = each.value.scan_on_push
}

tags = var.tags
tags = var.tags
}

resource "aws_ecr_lifecycle_policy" "this" {
for_each = { for k, v in var.repositories : k => v if length(v.lifecycle_policies) > 0 }
for_each = { for k, v in var.repositories : k => v if length(v.lifecycle_policies) > 0 }

repository = aws_ecr_repository.this[each.key].name
repository = aws_ecr_repository.this[each.key].name

policy = jsonencode({
rules = [
policy = jsonencode({
rules = [
for policy in each.value.lifecycle_policies : merge({
rulePriority = index(each.value.lifecycle_policies, policy) + 1
description = policy.description
selection = merge({
tagStatus = policy.tag_status
countType = "sinceImagePushed"
countUnit = policy.count_unit
countNumber = policy.count_number
rulePriority = index(each.value.lifecycle_policies, policy) + 1
description = policy.description
selection = merge({
tagStatus = policy.tag_status
countType = "sinceImagePushed"
countUnit = policy.count_unit
countNumber = policy.count_number
},
policy.tag_status == "tagged" ? {
tagPrefixList = "${policy.tagPrefixLists}"
tagPrefixList = "${policy.tagPrefixLists}"
} : {})
action = {
type = "expire"
action = {
type = "expire"
}
})
]
Expand Down
26 changes: 13 additions & 13 deletions terragrunt/ACCOUNT_ID/us-east-1/demo/common/aws-ecr/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ terraform {
inputs = {
repositories = {
"${include.env.locals.name}" = {
image_tag_mutability = "MUTABLE"
scan_on_push = true
image_tag_mutability = "MUTABLE"
scan_on_push = true

lifecycle_policies = [
lifecycle_policies = [
{
tag_status = "tagged"
count_unit = "days"
count_number = 7
tagPrefixLists = ["${include.env.locals.name}"]
description = "Keep image for 7 days"
tag_status = "tagged"
count_unit = "days"
count_number = 7
tagPrefixLists = ["${include.env.locals.name}"]
description = "Keep image for 7 days"
},
{
tag_status = "untagged"
count_unit = "days"
count_number = 1
tagPrefixLists = []
description = "Keep image for 1 day"
tag_status = "untagged"
count_unit = "days"
count_number = 1
tagPrefixLists = []
description = "Keep image for 1 day"
}
]
}
Expand Down

0 comments on commit e0bf35a

Please sign in to comment.