A collection of Terraform modules for AWS Elastic Container Registry (ECR).
module "ecr" {
source = " github.com/asaphe/terraform-aws-ecr//repository?ref=v2.0.0"
name = " my-app"
image_tag_mutability = " IMMUTABLE"
scan_on_push = true
tags = {
Environment = " production"
ManagedBy = " terraform"
}
}
Repository with KMS Encryption
module "ecr" {
source = " github.com/asaphe/terraform-aws-ecr//repository?ref=v2.0.0"
name = " my-app"
encryption_type = " KMS"
kms_key = aws_kms_key. ecr . arn
scan_on_push = true
}
Repository with Lifecycle Policy
module "ecr_repo" {
source = " github.com/asaphe/terraform-aws-ecr//repository?ref=v2.0.0"
name = " my-app"
scan_on_push = true
}
module "ecr_lifecycle" {
source = " github.com/asaphe/terraform-aws-ecr//lifecycle_policy?ref=v2.0.0"
repository = module. ecr_repo . repository_url
policy = jsonencode ({
rules = [{
rulePriority = 1
description = " Keep last 30 images"
selection = {
tagStatus = " any"
countType = " imageCountMoreThan"
countNumber = 30
}
action = {
type = " expire"
}
}]
})
}
Name
Version
terraform
>= 1.5.7
aws
>= 5.0
Name
Description
Type
Default
Required
name
Name of the repository
string
-
yes
image_tag_mutability
Tag mutability setting. Must be MUTABLE or IMMUTABLE
string
"MUTABLE"
no
encryption_type
Encryption type. Valid values are AES256 or KMS
string
"AES256"
no
kms_key
ARN of the KMS key when encryption_type is KMS
string
null
no
scan_on_push
Whether images are scanned after being pushed
bool
true
no
tags
A map of tags to assign to the resource
map(string)
null
no
repository_delete_timeout
How long to wait for a repository to be deleted
string
"20m"
no
Name
Description
Type
Default
Required
repository
Name of the repository to apply the policy
string
-
yes
policy
The policy document as a JSON formatted string
string
-
yes
Name
Description
Type
Default
Required
policy
The policy document as a JSON formatted string
string
-
yes
replication_configuration
Name
Description
Type
Default
Required
replication_configuration
Replication configuration for a registry
any
-
yes
Name
Description
Type
Default
Required
repository
Name of the repository to apply the policy
string
-
yes
policy
The policy document as a JSON formatted string
string
-
yes
Name
Description
arn
Full ARN of the repository
registry_id
The registry ID where the repository was created
repository_url
The URL of the repository
Name
Description
repository
The name of the repository
repository_policy
The repository policy
registry_id
The registry ID where the repository was created
Apache 2.0 - See LICENSE for details.