-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
120 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# :camera: ECR | ||
|
||
Amazon Elastic Container Registry (ECR) is a fully-managed Docker container registry that makes it easy for developers to store, manage, and deploy Docker container images. | ||
|
||
For more information about `ECR` check [AWS Docs](https://aws.amazon.com/ecr/) | ||
|
||
## Gist | ||
|
||
This module defines ECR repo with tags and life cycle policy which removes N untagged images | ||
|
||
## Example usage | ||
|
||
```hcl | ||
provider "aws" { | ||
version = "~> 2.62" | ||
} | ||
module "tags" { | ||
source = "[email protected]:peak-ai/terraform-modules.git//tags?ref=v0.3.0" | ||
tenant = "new-client" | ||
stage = "latest" | ||
feature = "example" | ||
service = "example" | ||
} | ||
module "my_ecr" { | ||
source = "[email protected]:peak-ai/terraform-modules.git//ecr?ref=v0.3.0" | ||
name = "my_ecr" | ||
tags = module.tags.default | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
terraform { | ||
required_providers { | ||
aws = ">= 2.62" | ||
} | ||
} | ||
|
||
resource "aws_ecr_repository" "default" { | ||
name = var.name | ||
image_tag_mutability = var.image_tag_mutability | ||
image_scanning_configuration { | ||
scan_on_push = var.scan_on_push | ||
} | ||
tags = var.tags | ||
} | ||
|
||
resource "aws_ecr_lifecycle_policy" "default" { | ||
repository = aws_ecr_repository.default.name | ||
|
||
policy = <<EOF | ||
{ | ||
"rules": [ | ||
{ | ||
"rulePriority": 1, | ||
"description": "Keep only N untagged image, expire all others", | ||
"selection": { | ||
"tagStatus": "untagged", | ||
"countType": "imageCountMoreThan", | ||
"countNumber": ${var.untagged_images_to_keep} | ||
}, | ||
"action": { | ||
"type": "expire" | ||
} | ||
} | ||
] | ||
} | ||
EOF | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
output "name" { | ||
value = aws_ecr_repository.default.name | ||
description = "The name of the repository" | ||
} | ||
|
||
output "arn" { | ||
value = aws_ecr_repository.default.arn | ||
description = "Full ARN of the repository" | ||
} | ||
|
||
output "registry_id" { | ||
value = aws_ecr_repository.default.registry_id | ||
description = "The registry ID where the repository was created" | ||
} | ||
|
||
output "repository_url" { | ||
value = aws_ecr_repository.default.repository_url | ||
description = "The URL of the repository (in the form aws_account_id.dkr.ecr.region.amazonaws.com/repositoryName)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
variable "name" { | ||
type = string | ||
description = "Name of ECR bucket" | ||
} | ||
|
||
variable "image_tag_mutability" { | ||
type = string | ||
default = "MUTABLE" | ||
} | ||
|
||
variable "scan_on_push" { | ||
type = bool | ||
default = true | ||
} | ||
|
||
variable "untagged_images_to_keep" { | ||
type = number | ||
default = 5 | ||
} | ||
|
||
variable "tags" { | ||
description = "Tags to pass" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,18 +10,18 @@ This module definines minimal, secure S3 bucket configuration. | |
## Example usage | ||
|
||
```hcl | ||
provider "aws" { | ||
version = "~> 2.62" | ||
} | ||
module "tags" { | ||
source = "[email protected]:peak-ai/terraform-modules.git//tags?ref=v0.1.0" | ||
source = "[email protected]:peak-ai/terraform-modules.git//tags?ref=v0.2.0" | ||
tenant = "new-client" | ||
stage = "latest" | ||
feature = "example" | ||
service = "example" | ||
} | ||
provider "aws" { | ||
version = "~> 2.62" | ||
} | ||
module "my_s3" { | ||
source = "[email protected]:peak-ai/terraform-modules.git//s3?ref=v0.2.0" | ||
name = "s3" | ||
|