added ecr module to terraform repo

This commit is contained in:
Khalim Conn-Kowlessar 2023-08-22 09:19:56 +01:00
parent ad6ed75cc3
commit 517409dfe0
4 changed files with 44 additions and 1 deletions

View file

@ -98,4 +98,10 @@ module "route53" {
providers = {
aws.aws_use1 = aws.aws_use1
}
}
}
# Create an ECR repository for storage of the lambda's docker images
module "ecr" {
source = "./modules/ecr"
environment = var.stage
}

View file

@ -0,0 +1,29 @@
resource "aws_ecr_repository" "my_repository" {
name = "fastapi-repository-${var.environment}"
image_tag_mutability = "MUTABLE" # Allows overwriting image tags, change to IMMUTABLE if you want to prevent overwriting
image_scanning_configuration {
scan_on_push = true
}
}
resource "aws_ecr_lifecycle_policy" "my_repository_policy" {
repository = aws_ecr_repository.my_repository.name
policy = jsonencode({
rules = [
{
rulePriority = 1
description = "Retain only the last 10 images"
selection = {
tagStatus = "any"
countType = "imageCountMoreThan"
countNumber = 10
}
action = {
type = "expire"
}
}
]
})
}

View file

@ -0,0 +1,4 @@
output "ecr_repository_name" {
description = "Name of the EPR repo in AWS"
value = aws_ecr_repository.my_repository.name
}

View file

@ -0,0 +1,4 @@
variable "environment" {
description = "The environment for the ECR repository (dev or prod)"
type = string
}