Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.tfstate.backup
*.tfvars
.terraform.lock.hcl
modules/shared_resources/dist/*.zip

# --- Secrets (보안상 절대 커밋 금지) ---
*.pem
Expand Down
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@ solid-connection-infra/
│ └── secrets/ # 민감한 data 관리
│ └── ...
├── modules/
│ └── app_stack/ # [Prod/Stage 환경의 공통 모듈]
│ ├── security_groups.tf
│ ├── ec2.tf
│ ├── rds.tf
│ ├── app_stack/ # [Prod/Stage 환경의 공통 모듈]
│ │ ├── security_groups.tf
│ │ ├── ec2.tf
│ │ ├── rds.tf
│ │ ├── variables.tf
│ │ └── outputs.tf
│ └── shared_resources/ # [global 환경의 공유 자원 모듈]
│ ├── src/
│ │ ├── img_resizing/
│ │ │ └── index.js
│ │ └── thumbnail/
│ │ └── index.js
│ ├── cloudfront.tf
│ ├── lambda.tf
│ ├── provider.tf
│ ├── s3.tf
│ ├── variables.tf
│ └── outputs.tf
│ └── variables.tf
└── environments/
├── prod/ # [Prod 환경]
│ ├── main.tf
Expand All @@ -29,7 +39,11 @@ solid-connection-infra/
│ ├── main.tf
│ ├── provider.tf
│ └── variables.tf
└── monitoring/ # [Monitoring 환경]
├── monitoring/ # [부하테스트 환경]
│ ├── main.tf
│ ├── provider.tf
│ └── variables.tf
└── global/ # [global 공유 환경]
├── main.tf
├── provider.tf
└── variables.tf
Expand Down
2 changes: 1 addition & 1 deletion config/secrets
25 changes: 25 additions & 0 deletions environment/global/main.tf
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
}
21 changes: 21 additions & 0 deletions environment/global/provider.tf
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"
}
}
}
71 changes: 71 additions & 0 deletions environment/global/variables.tf
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)
}

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
}
4 changes: 0 additions & 4 deletions environment/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,4 @@ module "prod_stack" {
domain_name = var.domain_name
cert_email = var.cert_email
nginx_conf_name = var.nginx_conf_name

# S3 버킷 이름 전달
s3_default_bucket_name = var.s3_default_bucket_name
s3_upload_bucket_name = var.s3_upload_bucket_name
}
10 changes: 0 additions & 10 deletions environment/prod/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,3 @@ variable "nginx_conf_name" {
description = "Nginx conf name for the prod environment"
type = string
}

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
}
4 changes: 0 additions & 4 deletions environment/stage/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,4 @@ module "stage_stack" {
domain_name = var.domain_name
cert_email = var.cert_email
nginx_conf_name = var.nginx_conf_name

# S3 버킷 이름 전달
s3_default_bucket_name = var.s3_default_bucket_name
s3_upload_bucket_name = var.s3_upload_bucket_name
}
10 changes: 0 additions & 10 deletions environment/stage/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,3 @@ variable "nginx_conf_name" {
description = "Nginx conf name for the stage environment"
type = string
}

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
}
11 changes: 0 additions & 11 deletions modules/app_stack/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,3 @@ variable "nginx_conf_name" {
description = "Nginx config filename"
type = string
}

# [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
}
97 changes: 97 additions & 0 deletions modules/shared_resources/cloudfront.tf
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"

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"
}
}

# 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"

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"
}
}
Loading