Hi @SanjuMLGeek ,
it would be helpful if you could reformat your code (enclose it in tripple backticks).
As per my understanding you cannot use count for creating multiple policies of the same ECR. So all rules have to be created within the policy section.
I assume your initial error points to a type mismatch for tag_prefix_list
. It should be a list instead of a string.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
# version = "= 3.24.1"
}
}
}
resource "aws_ecr_repository" "foo" {
name = "bar"
}
resource "aws_ecr_lifecycle_policy" "foopolicy" {
repository = aws_ecr_repository.foo.name
policy = jsonencode({ "rules" : var.lifecycle_rules })
}
variable "lifecycle_rules" {
default = [{
rule_priority = 1
tag_status = "tagged"
tag_prefix_list = ["test", "test1", "test2"]
count_type = "sinceImagePushed"
count_number = 60
},
{
rule_priority = 2
tag_status = "tagged"
tag_prefix_list = ["prod", "prod1", "prod2"]
count_type = "sinceImagePushed"
count_number = 90
}]
}