-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Lambda와 CloudFront를 TF로 관리하도록 Migrate #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d2ae250
3cde4d0
aa4342c
fccc099
8dd2512
a15bba1
5add933
3a46f1c
ee4f2f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| module "shared_resources" { | ||
| source = "../../modules/shared_resources" | ||
|
|
||
| providers = { | ||
| aws = aws | ||
| } | ||
|
|
||
| s3_default_bucket_name = var.s3_default_bucket_name | ||
| s3_upload_bucket_name = var.s3_upload_bucket_name | ||
|
|
||
| resizing_img_func_name = var.resizing_img_func_name | ||
| resizing_img_func_role = var.resizing_img_func_role | ||
| resizing_img_func_handler = var.resizing_img_func_handler | ||
| resizing_img_func_runtime = var.resizing_img_func_runtime | ||
| resizing_img_func_layers = var.resizing_img_func_layers | ||
|
|
||
| thumbnail_generating_func_name = var.thumbnail_generating_func_name | ||
| thumbnail_generating_func_role = var.thumbnail_generating_func_role | ||
| thumbnail_generating_func_handler = var.thumbnail_generating_func_handler | ||
| thumbnail_generating_func_runtime = var.thumbnail_generating_func_runtime | ||
| thumbnail_generating_func_layers = var.thumbnail_generating_func_layers | ||
|
|
||
| default_cdn_web_acl_id = var.default_cdn_web_acl_id | ||
| upload_cdn_web_acl_id = var.upload_cdn_web_acl_id | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| terraform { | ||
| required_version = ">= 1.0.0" | ||
|
|
||
| required_providers { | ||
| aws = { | ||
| source = "hashicorp/aws" | ||
| version = "~> 5.0" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| provider "aws" { | ||
| region = "ap-northeast-2" | ||
|
|
||
| default_tags { | ||
| tags = { | ||
| Project = "solid-connection" | ||
| Environment = "global" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,71 @@ | ||||||||||||||||||
| # [S3 버킷 관련 변수] | ||||||||||||||||||
| variable "s3_default_bucket_name" { | ||||||||||||||||||
| description = "Name of the default S3 bucket" | ||||||||||||||||||
| type = string | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| variable "s3_upload_bucket_name" { | ||||||||||||||||||
| description = "Name of the upload S3 bucket" | ||||||||||||||||||
| type = string | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| # [Lambda 관련 변수] | ||||||||||||||||||
| variable "resizing_img_func_name" { | ||||||||||||||||||
| description = "Image Resizing function name for uploaded s3 file" | ||||||||||||||||||
| type = string | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| variable "resizing_img_func_role" { | ||||||||||||||||||
| description = "Image Resizing function role for uploaded s3 file" | ||||||||||||||||||
| type = string | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| variable "resizing_img_func_handler" { | ||||||||||||||||||
| description = "Image Resizing function handler for uploaded s3 file" | ||||||||||||||||||
| type = string | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| variable "resizing_img_func_runtime" { | ||||||||||||||||||
| description = "Image Resizing function runtime for uploaded s3 file" | ||||||||||||||||||
| type = string | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| variable "thumbnail_generating_func_name" { | ||||||||||||||||||
| description = "Thumbnail generating function name for uploaded s3 file" | ||||||||||||||||||
| type = string | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| variable "thumbnail_generating_func_role" { | ||||||||||||||||||
| description = "Thumbnail generating function role for uploaded s3 file" | ||||||||||||||||||
| type = string | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| variable "thumbnail_generating_func_handler" { | ||||||||||||||||||
| description = "Thumbnail generating function handler for uploaded s3 file" | ||||||||||||||||||
| type = string | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| variable "thumbnail_generating_func_runtime" { | ||||||||||||||||||
| description = "Thumbnail generating function runtime for uploaded s3 file" | ||||||||||||||||||
| type = string | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| variable "resizing_img_func_layers" { | ||||||||||||||||||
| description = "Layers For Image Resizing func" | ||||||||||||||||||
| type = list(string) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| variable "thumbnail_generating_func_layers" { | ||||||||||||||||||
| description = "Layers For Image Resizing func" | ||||||||||||||||||
| type = list(string) | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+58
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy-paste error in variable description. The description says "Layers For Image Resizing func" but this variable is for 🔎 Recommended fix variable "thumbnail_generating_func_layers" {
- description = "Layers For Image Resizing func"
+ description = "Layers For Thumbnail Generating func"
type = list(string)
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| variable "default_cdn_web_acl_id" { | ||||||||||||||||||
| description = "WAF Web ACL Id for Default Cloudfront CDN" | ||||||||||||||||||
| type = string | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| variable "upload_cdn_web_acl_id" { | ||||||||||||||||||
| description = "WAF Web ACL Id for Upload Cloudfront CDN" | ||||||||||||||||||
| type = string | ||||||||||||||||||
| } | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,97 @@ | ||||||||||||||||||
| # 1. CDN for Default Bucket | ||||||||||||||||||
| resource "aws_cloudfront_distribution" "default_cdn" { | ||||||||||||||||||
| enabled = true | ||||||||||||||||||
| is_ipv6_enabled = true | ||||||||||||||||||
| comment = "solid-connection s3 default cloudfront" | ||||||||||||||||||
| price_class = "PriceClass_All" | ||||||||||||||||||
| http_version = "http2" | ||||||||||||||||||
|
|
||||||||||||||||||
| web_acl_id = var.default_cdn_web_acl_id | ||||||||||||||||||
|
|
||||||||||||||||||
| tags = { | ||||||||||||||||||
| "Name" = "solid-connection s3 default cloudfront" | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| origin { | ||||||||||||||||||
| domain_name = "${var.s3_default_bucket_name}.s3.ap-northeast-2.amazonaws.com" | ||||||||||||||||||
| origin_id = "${var.s3_default_bucket_name}.s3.ap-northeast-2.amazonaws.com-mjo1g7tk2w8" # 기존 ID 유지 | ||||||||||||||||||
| origin_access_control_id = "E14M8OP55A3YO7" | ||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hard-coded Origin Access Control ID prevents Terraform management. The 🔎 Recommended fix: Import or create OAC resourceOption 1: Import existing OAC (recommended for migration) Add a data source to reference the existing OAC: +data "aws_cloudfront_origin_access_control" "default_oac" {
+ id = "E14M8OP55A3YO7"
+}
+
resource "aws_cloudfront_distribution" "default_cdn" {
# ...
origin {
domain_name = "${var.s3_default_bucket_name}.s3.ap-northeast-2.amazonaws.com"
origin_id = "${var.s3_default_bucket_name}.s3.ap-northeast-2.amazonaws.com-mjo1g7tk2w8"
- origin_access_control_id = "E14M8OP55A3YO7"
+ origin_access_control_id = data.aws_cloudfront_origin_access_control.default_oac.idOption 2: Create new OAC resource resource "aws_cloudfront_origin_access_control" "default_oac" {
name = "solid-connection-default-oac"
origin_access_control_origin_type = "s3"
signing_behavior = "always"
signing_protocol = "sigv4"
}Then reference it: - origin_access_control_id = "E14M8OP55A3YO7"
+ origin_access_control_id = aws_cloudfront_origin_access_control.default_oac.id
🧰 Tools🪛 Gitleaks (8.30.0)[high] 18-18: Detected a Generic API Key, potentially exposing access to various services and sensitive operations. (generic-api-key) |
||||||||||||||||||
|
|
||||||||||||||||||
| connection_attempts = 3 | ||||||||||||||||||
| connection_timeout = 10 | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| default_cache_behavior { | ||||||||||||||||||
| target_origin_id = "${var.s3_default_bucket_name}.s3.ap-northeast-2.amazonaws.com-mjo1g7tk2w8" # 위 origin_id와 같아야 함 | ||||||||||||||||||
| viewer_protocol_policy = "redirect-to-https" | ||||||||||||||||||
| compress = true | ||||||||||||||||||
|
|
||||||||||||||||||
| allowed_methods = ["GET", "HEAD"] | ||||||||||||||||||
| cached_methods = ["GET", "HEAD"] | ||||||||||||||||||
|
|
||||||||||||||||||
| cache_policy_id = "658327ea-f89d-4fab-a63d-7e88639e58f6" | ||||||||||||||||||
|
|
||||||||||||||||||
| smooth_streaming = false | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| restrictions { | ||||||||||||||||||
| geo_restriction { | ||||||||||||||||||
| restriction_type = "none" | ||||||||||||||||||
| locations = [] | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| viewer_certificate { | ||||||||||||||||||
| cloudfront_default_certificate = true | ||||||||||||||||||
| minimum_protocol_version = "TLSv1" | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+44
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TLSv1 is deprecated and insecure. The minimum TLS protocol version is set to TLSv1, which has known security vulnerabilities and is deprecated. AWS recommends TLSv1.2 as the minimum. 🔎 Recommended security fix viewer_certificate {
cloudfront_default_certificate = true
- minimum_protocol_version = "TLSv1"
+ minimum_protocol_version = "TLSv1.2_2021"
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| # 2. CDN for Upload Bucket | ||||||||||||||||||
| resource "aws_cloudfront_distribution" "upload_cdn" { | ||||||||||||||||||
| enabled = true | ||||||||||||||||||
| is_ipv6_enabled = true | ||||||||||||||||||
| comment = "solid-connection s3 upload cloudfront" | ||||||||||||||||||
| price_class = "PriceClass_All" | ||||||||||||||||||
| http_version = "http2" | ||||||||||||||||||
|
|
||||||||||||||||||
| web_acl_id = var.upload_cdn_web_acl_id | ||||||||||||||||||
|
|
||||||||||||||||||
| tags = { | ||||||||||||||||||
| "Name" = "solid-connection s3 upload cloudfront" | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| origin { | ||||||||||||||||||
| domain_name = "${var.s3_upload_bucket_name}.s3.ap-northeast-2.amazonaws.com" | ||||||||||||||||||
| origin_id = "${var.s3_upload_bucket_name}.s3.ap-northeast-2.amazonaws.com-mjo1jpx6rvc" | ||||||||||||||||||
| origin_access_control_id = "E1ZBB5RMSBZQ4I" | ||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hard-coded Origin Access Control ID prevents Terraform management. Same issue as the default_cdn distribution - the OAC ID is hard-coded. This should be managed through Terraform for consistency and infrastructure-as-code best practices. 🔎 Recommended fix: Import or create OAC resourceOption 1: Import existing OAC +data "aws_cloudfront_origin_access_control" "upload_oac" {
+ id = "E1ZBB5RMSBZQ4I"
+}
+
resource "aws_cloudfront_distribution" "upload_cdn" {
# ...
origin {
domain_name = "${var.s3_upload_bucket_name}.s3.ap-northeast-2.amazonaws.com"
origin_id = "${var.s3_upload_bucket_name}.s3.ap-northeast-2.amazonaws.com-mjo1jpx6rvc"
- origin_access_control_id = "E1ZBB5RMSBZQ4I"
+ origin_access_control_id = data.aws_cloudfront_origin_access_control.upload_oac.idOption 2: Create new OAC resource resource "aws_cloudfront_origin_access_control" "upload_oac" {
name = "solid-connection-upload-oac"
origin_access_control_origin_type = "s3"
signing_behavior = "always"
signing_protocol = "sigv4"
}
|
||||||||||||||||||
|
|
||||||||||||||||||
| connection_attempts = 3 | ||||||||||||||||||
| connection_timeout = 10 | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| default_cache_behavior { | ||||||||||||||||||
| target_origin_id = "${var.s3_upload_bucket_name}.s3.ap-northeast-2.amazonaws.com-mjo1jpx6rvc" | ||||||||||||||||||
| viewer_protocol_policy = "redirect-to-https" | ||||||||||||||||||
| compress = true | ||||||||||||||||||
|
|
||||||||||||||||||
| allowed_methods = ["GET", "HEAD"] | ||||||||||||||||||
| cached_methods = ["GET", "HEAD"] | ||||||||||||||||||
|
|
||||||||||||||||||
| cache_policy_id = "658327ea-f89d-4fab-a63d-7e88639e58f6" | ||||||||||||||||||
|
|
||||||||||||||||||
| smooth_streaming = false | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| restrictions { | ||||||||||||||||||
| geo_restriction { | ||||||||||||||||||
| restriction_type = "none" | ||||||||||||||||||
| locations = [] | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| viewer_certificate { | ||||||||||||||||||
| cloudfront_default_certificate = true | ||||||||||||||||||
| minimum_protocol_version = "TLSv1" | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+93
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TLSv1 is deprecated and insecure. Same security issue as default_cdn - TLSv1 should be upgraded to at least TLSv1.2_2021. 🔎 Recommended security fix viewer_certificate {
cloudfront_default_certificate = true
- minimum_protocol_version = "TLSv1"
+ minimum_protocol_version = "TLSv1.2_2021"
}🤖 Prompt for AI Agents |
||||||||||||||||||
| } | ||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect comment for monitoring environment.
The comment "부하테스트 환경" (load test environment) is duplicated from
load_test/. Themonitoring/directory should have its own description, likely "모니터링 환경" or similar.🔎 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents