Skip to content

Commit

Permalink
Merge pull request #16 from kookmin-sw/mhsong-dev
Browse files Browse the repository at this point in the history
API IaC 코드 추가 / 수정
  • Loading branch information
mh3ong authored Mar 28, 2024
2 parents eafc9fb + 99c2c47 commit f98b0bc
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 0 deletions.
36 changes: 36 additions & 0 deletions IaC/serverless_api_template/lambda/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,42 @@ resource "aws_iam_role_policy_attachment" "lambda_basic_policy" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}

resource "aws_iam_role_policy_attachment" "cloudwatch_policy" {
count = var.attach_cloudwatch_policy
role = aws_iam_role.lambda-role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/CloudWatchFullAccess"
}

resource "aws_iam_role_policy_attachment" "cloudwatchlogs_policy" {
count = var.attach_cloudwatch_policy
role = aws_iam_role.lambda-role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/CloudWatchLogsFullAccess"
}

resource "aws_iam_role_policy_attachment" "ec2_policy" {
count = var.attach_ec2_policy
role = aws_iam_role.lambda-role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2FullAccess"
}

resource "aws_iam_role_policy_attachment" "vpc_policy" {
count = var.attach_vpc_policy
role = aws_iam_role.lambda-role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonVPCFullAccess"
}

resource "aws_iam_role_policy_attachment" "s3_policy" {
count = var.attach_s3_policy
role = aws_iam_role.lambda-role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonS3FullAccess"
}

resource "aws_iam_role_policy_attachment" "lambda_policy" {
count = var.attach_lambda_policy
role = aws_iam_role.lambda-role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambda_FullAccess"
}

resource "aws_lambda_function" "lambda" {
function_name = "${var.prefix}-aws-lambda"
package_type = "Image"
Expand Down
5 changes: 5 additions & 0 deletions IaC/serverless_api_template/lambda/var.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ variable "container_registry" {}
variable "container_repository" {}
variable "container_image_tag" {}
variable "ram_mib" {}
variable "attach_cloudwatch_policy" {}
variable "attach_ec2_policy" {}
variable "attach_lambda_policy" {}
variable "attach_s3_policy" {}
variable "attach_vpc_policy" {}
25 changes: 25 additions & 0 deletions IaC/serverless_api_template/var.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,28 @@ variable "lambda_ram_size" {
type = number
default = 2048
}

variable "attach_ec2_policy" {
type = bool
default = false
}

variable "attach_s3_policy" {
type = bool
default = false
}

variable "attach_vpc_policy" {
type = bool
default = false
}

variable "attach_lambda_policy" {
type = bool
default = false
}

variable "attach_cloudwatch_policy" {
type = bool
default = false
}
41 changes: 41 additions & 0 deletions automation/serverless_inference_deploy/IaC/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

module "serverless_inference_deploy" {
source = "github.com/kookmin-sw/capstone-2024-12//IaC/serverless_api_template"
prefix = "serverless_inference_deploy"
container_registry = "694448341573.dkr.ecr.ap-northeast-2.amazonaws.com"
container_repository = "serverless-inference-deploy"
container_image_tag = "latest"
lambda_ram_size = 2048
attach_s3_policy = true
attach_ec2_policy = true
attach_lambda_policy = true
attach_cloudwatch_policy = true
}

variable "region" {
type = string
default = "ap-northeast-2"
}

variable "awscli_profile" {
type = string
default = "default"
}

output "function_url" {
value = module.serverless_inference.function_url
}

provider "aws" {
region = var.region
profile = var.awscli_profile
}

terraform {
backend "s3" {
bucket = "sskai-terraform-state"
key = "serverless_inference_deploy/tf.state"
region = "ap-northeast-2"
encrypt = true
}
}
54 changes: 54 additions & 0 deletions recommend/family_recommend/IaC/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

module "cpu_family_recommend" {
source = "github.com/kookmin-sw/capstone-2024-12//IaC/serverless_api_template"
prefix = "cpu_family_recommend"
container_registry = "694448341573.dkr.ecr.ap-northeast-2.amazonaws.com"
container_repository = "recommend-inference-cpu-family"
container_image_tag = "latest"
lambda_ram_size = 2048
attach_s3_policy = true
attach_ec2_policy = true
}

module "gpu_family_recommend" {
source = "github.com/kookmin-sw/capstone-2024-12//IaC/serverless_api_template"
prefix = "gpu_family_recommend"
container_registry = "694448341573.dkr.ecr.ap-northeast-2.amazonaws.com"
container_repository = "recommend-inference-gpu-family"
container_image_tag = "latest"
lambda_ram_size = 2048
attach_s3_policy = true
attach_ec2_policy = true
}

variable "region" {
type = string
default = "ap-northeast-2"
}

variable "awscli_profile" {
type = string
default = "default"
}

output "cpu_recommend_function_url" {
value = module.cpu_family_recommend.function_url
}

output "gpu_recommend_function_url" {
value = module.gpu_family_recommend.function_url
}

provider "aws" {
region = var.region
profile = var.awscli_profile
}

terraform {
backend "s3" {
bucket = "sskai-terraform-state"
key = "family_recommend/tf.state"
region = "ap-northeast-2"
encrypt = true
}
}

0 comments on commit f98b0bc

Please sign in to comment.