Skip to content

Commit

Permalink
add: ecr module
Browse files Browse the repository at this point in the history
  • Loading branch information
josephgoksu committed May 30, 2023
1 parent 7d99ea6 commit 01acdf5
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 1 deletion.
84 changes: 84 additions & 0 deletions modules/ecr/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Create an ECR repository named "my-ecr-repo"
resource "aws_ecr_repository" "ecr_repo" {
name = "${var.project_name}-ecr-repo"
}

# Create an IAM role named "ecr-role" that can be assumed by the ECR service
resource "aws_iam_role" "ecr_role" {
name = "ecr-role"

assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "ecr.amazonaws.com"
}
}
]
})
}

# Create an IAM policy named "ecr-policy" that allows various ECR actions
resource "aws_iam_policy" "ecr_policy" {
name = "${var.project_name}-ecr-policy"

policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:GetRepositoryPolicy",
"ecr:DescribeRepositories",
"ecr:ListImages",
"ecr:DescribeImages",
"ecr:BatchGetImage",
"ecr:InitiateLayerUpload",
"ecr:UploadLayerPart",
"ecr:CompleteLayerUpload",
"ecr:PutImage"
]
Effect = "Allow"
Resource = "*"
}
]
})
}

# Attach the "ecr-policy" to the "ecr-role"
resource "aws_iam_role_policy_attachment" "ecr_role_policy_attachment" {
policy_arn = aws_iam_policy.ecr_policy.arn
role = aws_iam_role.ecr_role.name
}

# Create a policy for the "my-ecr-repo" repository that allows various ECR actions for all AWS accounts
resource "aws_ecr_repository_policy" "ecr_repo_policy" {
repository = aws_ecr_repository.ecr_repo.name

policy = jsonencode({
Version = "2008-10-17"
Statement = [
{
Sid = "AllowPushPull"
Effect = "Allow"
Principal = {
AWS = "*"
}
Action = [
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"ecr:BatchCheckLayerAvailability",
"ecr:PutImage",
"ecr:InitiateLayerUpload",
"ecr:UploadLayerPart",
"ecr:CompleteLayerUpload"
]
}
]
})
}
Empty file added modules/ecr/outputs.tf
Empty file.
4 changes: 4 additions & 0 deletions modules/ecr/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "project_name" {
description = "Project name"
type = string
}
2 changes: 1 addition & 1 deletion modules/eks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module "eks" {

# Addon: EBS CSI driver
module "ebs_csi_driver" {

# Enable the EBS CSI driver if the "enable_ebs_csi_driver" variable is set to true
count = var.enable_ebs_csi_driver ? 1 : 0

# Use the EKS addons module to add the EBS CSI driver to the cluster
Expand Down

0 comments on commit 01acdf5

Please sign in to comment.