Skip to content

Commit

Permalink
ADDED ECR module
Browse files Browse the repository at this point in the history
  • Loading branch information
azhar22k committed Jun 14, 2020
1 parent 6568087 commit be6e38a
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 7 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ This repo list some open to use Terraform modules we use at `Peak AI` because we

## List of avilable modules

- [:bookmark: tags (aka labels)](/tags)
- [:open_file_folder: s3](/s3)

- AWS
- [:open_file_folder: S3](/s3)
- [:camera: ECR](/ecr)
- Miscleneous
- [:bookmark: Tags (aka Labels)](/tags)

## Example usage

Expand Down
30 changes: 30 additions & 0 deletions ecr/README.md
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
}
```
37 changes: 37 additions & 0 deletions ecr/main.tf
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
}
19 changes: 19 additions & 0 deletions ecr/outputs.tf
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)"
}
23 changes: 23 additions & 0 deletions ecr/variables.tf
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"
}
10 changes: 5 additions & 5 deletions s3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit be6e38a

Please sign in to comment.