Open malinoff opened 1 year ago
Voting for Prioritization
Volunteering to Work on This Issue
Removing aws_ecr_lifecycle_policy.main
from the .tf file results in a plan being successfully produced.
Looks like it crashes only because the lifecycle policy is malformed. Same crash happened when I imported the policy to the state file. Either removing the policy resource or specifying a correct policy works.
Also experiencing this. Still haven't determined what a correct policy looks like, but the error messages were not very helpful. The only hint was that it started happening after adding the lifecycle policy.
Edit: The following succeeded in applying:
resource "aws_ecr_repository" "api" {
name = "api"
image_tag_mutability = "MUTABLE"
image_scanning_configuration {
scan_on_push = true
}
}
resource "aws_ecr_repository" "nginx" {
name = "nginx"
image_tag_mutability = "MUTABLE"
image_scanning_configuration {
scan_on_push = true
}
}
data "aws_ecr_lifecycle_policy_document" "limit_images" {
rule {
priority = 1
description = "Keep only the most recent untagged image"
selection {
count_type = "imageCountMoreThan"
count_number = 1
tag_status = "untagged"
}
action {
type = "expire"
}
}
rule {
priority = 2
description = "Keep only the 5 most recent tagged images"
selection {
count_type = "imageCountMoreThan"
count_number = 5
tag_status = "tagged"
tag_pattern_list = ["*"]
}
}
}
resource "aws_ecr_lifecycle_policy" "api" {
repository = aws_ecr_repository.api.name
policy = data.aws_ecr_lifecycle_policy_document.limit_images.json
}
resource "aws_ecr_lifecycle_policy" "nginx" {
repository = aws_ecr_repository.nginx.name
policy = data.aws_ecr_lifecycle_policy_document.limit_images.json
}
Terraform does not tell you that tag_pattern_list
is required when tag_status = "tagged"
. I have not confirmed that this works as intended, just that it applied successfully.
Terraform Core Version
1.3.9
AWS Provider Version
4.54.0
Affected Resource(s)
Expected Behavior
Terraform is able to import existing ECR repository and its lifecycle policy.
Actual Behavior
Terraform crashed.
Relevant Error/Panic Output Snippet
Terraform Configuration Files
The following data was added to the state file (replaced sensitive values with
<>
):Steps to Reproduce
I'm trying to import existing resources. I've specified the following resource definitions:
Then I've imported the repository with the following command:
Then I executed
terraform plan
to see the plan. I expected to either see an error (something about the lifecycle policy being invalid/unavailable/unmanaged) or a plan to add this lifecycle policy (since I haven't imported it yet).Debug Output
No response
Panic Output
No response
Important Factoids
No response
References
No response
Would you like to implement a fix?
None