Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
ci: Add ECR container registry
Browse files Browse the repository at this point in the history
  • Loading branch information
dannevesdantas committed Mar 14, 2024
1 parent 87dee50 commit 51cc59b
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 2 deletions.
11 changes: 11 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
provider "aws" {
region = local.region
}

locals {
region = "us-east-1"

Expand Down Expand Up @@ -44,6 +48,13 @@ module "cluster_k8s" {
tags = local.tags
}

module "registry" {
source = "./modules/registry"

region = local.region
tags = local.tags
}

module "db" {
source = "./modules/db"

Expand Down
2 changes: 0 additions & 2 deletions modules/network/versions.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
terraform {
required_version = ">= 1.3"

required_providers {
aws = {
source = "hashicorp/aws"
Expand Down
37 changes: 37 additions & 0 deletions modules/registry/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
provider "aws" {
region = local.region
}

locals {
region = var.region
}

data "aws_caller_identity" "current" {}

module "ecr" {
source = "terraform-aws-modules/ecr/aws"
version = "~> 1.6"

repository_name = "rms"

repository_read_write_access_arns = [data.aws_caller_identity.current.arn]

repository_lifecycle_policy = jsonencode({
rules = [
{
rulePriority = 1,
description = "Keep last 30 images",
selection = {
tagStatus = "any",
countType = "imageCountMoreThan",
countNumber = 30
},
action = {
type = "expire"
}
}
]
})

tags = var.tags
}
4 changes: 4 additions & 0 deletions modules/registry/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "repository_url" {
description = "The URL of the repository (in the form aws_account_id.dkr.ecr.region.amazonaws.com/repositoryName)."
value = module.ecr.repository_url
}
10 changes: 10 additions & 0 deletions modules/registry/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
variable "region" {
default = "us-east-1"
description = "AWS region"
}

variable "tags" {
description = "Tags to set."
type = map(string)
default = {}
}
10 changes: 10 additions & 0 deletions modules/registry/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.3"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.40"
}
}
}
5 changes: 5 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ output "cluster_serviceaccount_name" {
value = module.cluster_k8s.serviceaccount_name
}

output "repository_url" {
description = "The URL of the repository (in the form aws_account_id.dkr.ecr.region.amazonaws.com/repositoryName)."
value = module.registry.repository_url
}

output "rds_endpoint" {
description = "RDS instance endpoint"
value = module.db.rds_endpoint
Expand Down

0 comments on commit 51cc59b

Please sign in to comment.