generated from nekochans/terraform-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from nekochans/feature/issue124
lgtm-cat-processorデプロイ用のリソースを構築
- Loading branch information
Showing
15 changed files
with
218 additions
and
11 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
modules/aws/iam/lgtm-cat-processor-deploy-role/files/policy.json
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,35 @@ | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"ecr:GetAuthorizationToken" | ||
], | ||
"Resource": "*" | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"ecr:BatchCheckLayerAvailability", | ||
"ecr:CompleteLayerUpload", | ||
"ecr:InitiateLayerUpload", | ||
"ecr:PutImage", | ||
"ecr:UploadLayerPart", | ||
"ecr:GetDownloadUrlForLayer", | ||
"ecr:BatchGetImage" | ||
], | ||
"Resource": "arn:aws:ecr:${region}:${account_id}:repository/*" | ||
}, | ||
{ | ||
"Effect":"Allow", | ||
"Action":[ | ||
"codebuild:StartBuild", | ||
"codebuild:BatchGetBuilds" | ||
], | ||
"Resource":[ | ||
"arn:aws:codebuild:${region}:${account_id}:project/*" | ||
] | ||
} | ||
] | ||
} |
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,38 @@ | ||
data "aws_iam_policy_document" "assume_role" { | ||
statement { | ||
effect = "Allow" | ||
actions = ["sts:AssumeRoleWithWebIdentity"] | ||
principals { | ||
type = "Federated" | ||
identifiers = [var.github_actions_oidc_provider_arn] | ||
} | ||
condition { | ||
test = "StringEquals" | ||
variable = "token.actions.githubusercontent.com:aud" | ||
values = ["sts.amazonaws.com"] | ||
} | ||
condition { | ||
test = "StringLike" | ||
variable = "token.actions.githubusercontent.com:sub" | ||
values = ["repo:nekochans/lgtm-cat-processor:*"] | ||
} | ||
} | ||
} | ||
|
||
resource "aws_iam_role" "deploy" { | ||
name = "lgtm-cat-processor-deploy-role" | ||
assume_role_policy = data.aws_iam_policy_document.assume_role.json | ||
} | ||
|
||
resource "aws_iam_policy" "deploy" { | ||
name = "lgtm-cat-processor-deploy-policy" | ||
policy = templatefile("${path.module}/files/policy.json", { | ||
region = data.aws_region.current.name | ||
account_id = data.aws_caller_identity.current.account_id | ||
}) | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "deploy" { | ||
role = aws_iam_role.deploy.name | ||
policy_arn = aws_iam_policy.deploy.arn | ||
} |
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,6 @@ | ||
variable "github_actions_oidc_provider_arn" { | ||
type = string | ||
} | ||
|
||
data "aws_region" "current" {} | ||
data "aws_caller_identity" "current" {} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
resource "aws_cloudwatch_log_group" "lgtm_image_processor" { | ||
name = "/aws/lambda/${local.lambda_function_name}" | ||
name = "/aws/lambda/${var.lambda_function_name}" | ||
retention_in_days = var.log_retention_in_days | ||
} |
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,36 @@ | ||
resource "aws_codebuild_project" "codebuild" { | ||
name = "${var.env}-${var.service_name}-deploy" | ||
build_timeout = 5 | ||
service_role = aws_iam_role.codebuild.arn | ||
|
||
environment { | ||
compute_type = "BUILD_LAMBDA_1GB" | ||
type = "ARM_LAMBDA_CONTAINER" | ||
image = "aws/codebuild/amazonlinux-aarch64-lambda-standard:python3.12" | ||
image_pull_credentials_type = "CODEBUILD" | ||
} | ||
|
||
# リポジトリで設定するので何もしない | ||
source { | ||
type = "NO_SOURCE" | ||
buildspec = <<BUILDSPEC | ||
version: 0.2 | ||
BUILDSPEC | ||
} | ||
|
||
artifacts { | ||
type = "NO_ARTIFACTS" | ||
} | ||
|
||
logs_config { | ||
cloudwatch_logs { | ||
status = "ENABLED" | ||
group_name = "/aws/codebuild/${var.env}-${var.service_name}-deploy" | ||
} | ||
} | ||
} | ||
|
||
resource "aws_cloudwatch_log_group" "codebuild" { | ||
name = "${var.env}-${var.service_name}-deploy" | ||
retention_in_days = var.log_retention_in_days | ||
} |
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,44 @@ | ||
data "aws_iam_policy_document" "codebuild_assume_role" { | ||
statement { | ||
actions = ["sts:AssumeRole"] | ||
effect = "Allow" | ||
principals { | ||
type = "Service" | ||
identifiers = ["codebuild.amazonaws.com"] | ||
} | ||
} | ||
} | ||
|
||
resource "aws_iam_role" "codebuild" { | ||
name = "${var.env}-${var.service_name}-deploy-service-role" | ||
assume_role_policy = data.aws_iam_policy_document.codebuild_assume_role.json | ||
} | ||
|
||
data "aws_iam_policy_document" "codebuild" { | ||
statement { | ||
effect = "Allow" | ||
actions = [ | ||
"logs:CreateLogGroup", | ||
"logs:CreateLogStream", | ||
"logs:PutLogEvents", | ||
] | ||
resources = [ | ||
"arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:/aws/codebuild/*" | ||
] | ||
} | ||
|
||
statement { | ||
effect = "Allow" | ||
actions = [ | ||
"lambda:UpdateFunctionCode", | ||
"lambda:GetFunctionConfiguration" | ||
] | ||
resources = ["arn:aws:lambda:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:function:${var.lambda_function_name}"] | ||
} | ||
} | ||
|
||
resource "aws_iam_role_policy" "codebuild" { | ||
name = "deploy-policy" | ||
role = aws_iam_role.codebuild.id | ||
policy = data.aws_iam_policy_document.codebuild.json | ||
} |
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,15 @@ | ||
variable "env" { | ||
type = string | ||
} | ||
variable "service_name" { | ||
type = string | ||
} | ||
variable "lambda_function_name" { | ||
type = string | ||
} | ||
variable "log_retention_in_days" { | ||
type = number | ||
} | ||
|
||
data "aws_region" "current" {} | ||
data "aws_caller_identity" "current" {} |
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
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
21 changes: 18 additions & 3 deletions
21
providers/aws/environments/stg/22-lgtm-image-processor/.terraform.lock.hcl
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -2,6 +2,6 @@ terraform { | |
required_version = "1.0.3" | ||
|
||
required_providers { | ||
aws = "5.1.0" | ||
aws = "5.68.0" | ||
} | ||
} |