create ECR repo + GHA IAM resources

This commit is contained in:
teddy931130 2025-01-15 19:17:48 +02:00
parent 0314b209b2
commit 7076b61c4a
2 changed files with 114 additions and 0 deletions

View file

@ -0,0 +1,46 @@
module "ecr_go-ethereum" {
source = "terraform-aws-modules/ecr/aws"
version = "2.3.1"
repository_name = "limechain-devops-task/go-ethereum"
repository_type = "private"
repository_read_write_access_arns = ["arn:aws:iam::${var.account_id}:role/${aws_iam_role.go-ethereum_github_actions.name}"]
create_repository_policy = true
repository_lifecycle_policy = jsonencode({
rules = [
{
rulePriority = 1,
description = "Keep last 20 images",
selection = {
tagStatus = "any",
countType = "imageCountMoreThan",
countNumber = 20
},
action = {
type = "expire"
}
}
]
})
# Registry Scanning Configuration
manage_registry_scanning_configuration = true
registry_scan_type = "BASIC"
registry_scan_rules = [
{
scan_frequency = "SCAN_ON_PUSH"
filter = [
{
filter = "*"
filter_type = "WILDCARD"
}
]
}
]
tags = {
"Name" = "limechain-devops-task"
"Environment" = var.env
}
}

View file

@ -0,0 +1,68 @@
### IAM for go-ethereum Github Actions
resource "aws_iam_role" "go-ethereum_github_actions" {
name = "go-ethereum-github-actions-role"
assume_role_policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Effect = "Allow",
Principal = {
Federated = "arn:aws:iam::${var.account_id}:oidc-provider/token.actions.githubusercontent.com"
},
Action = "sts:AssumeRoleWithWebIdentity",
Condition = {
StringLike = {
"token.actions.githubusercontent.com:sub" : "repo:teddy931130/go-ethereum:*"
},
StringEquals = {
"token.actions.githubusercontent.com:aud" : "sts.amazonaws.com",
}
}
}
]
})
tags = {
"Name" = "go-ethereum"
"Environment" = var.env
}
}
resource "aws_iam_policy" "go-ethereum_github_actions_policy" {
name = "limechain-go-ethereum-github-actions-ecr-policy"
description = "Permissions for Limechain-go-ethereum GitHub Actions to pull images from ECR"
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Effect = "Allow",
Action = [
"ecr:BatchCheckLayerAvailability",
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer",
"ecr:DescribeImages",
"ecr:InitiateLayerUpload",
"ecr:UploadLayerPart",
"ecr:CompleteLayerUpload",
"ecr:PutImage",
],
Resource = "arn:aws:ecr:${var.region}:${var.account_id}:repository/limechain-devops-task/go-ethereum"
},
{
Effect = "Allow",
Action = [
"ecr:GetAuthorizationToken"
],
Resource = "*"
}
]
})
}
resource "aws_iam_role_policy_attachment" "go-ethereum_github_actions_attach" {
role = aws_iam_role.go-ethereum_github_actions.name
policy_arn = aws_iam_policy.go-ethereum_github_actions_policy.arn
}