-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Prod MySQL S3 백업 인프라 구성 #69
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -15,3 +15,6 @@ modules/shared_resources/dist/*.zip | |
| # --- IDE & OS --- | ||
| .idea/ | ||
| .DS_Store | ||
|
|
||
| # --- AGENTS --- | ||
| AGENTS.local.md | ||
Submodule secrets
updated
from c1eaa9 to c9f90e
This file contains hidden or 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 hidden or 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,173 @@ | ||
| resource "aws_s3_bucket" "mysql_backup" { | ||
| bucket = var.mysql_backup_bucket_name | ||
| force_destroy = false | ||
| object_lock_enabled = true | ||
|
|
||
| tags = { | ||
| Name = var.mysql_backup_bucket_name | ||
| } | ||
|
|
||
| lifecycle { | ||
| prevent_destroy = true | ||
| } | ||
| } | ||
|
|
||
| resource "aws_s3_bucket_ownership_controls" "mysql_backup" { | ||
| bucket = aws_s3_bucket.mysql_backup.id | ||
|
|
||
| rule { | ||
| object_ownership = "BucketOwnerEnforced" | ||
| } | ||
| } | ||
|
|
||
| resource "aws_s3_bucket_public_access_block" "mysql_backup" { | ||
| bucket = aws_s3_bucket.mysql_backup.id | ||
|
|
||
| block_public_acls = true | ||
| block_public_policy = true | ||
| ignore_public_acls = true | ||
| restrict_public_buckets = true | ||
| } | ||
|
|
||
| resource "aws_s3_bucket_policy" "mysql_backup" { | ||
| bucket = aws_s3_bucket.mysql_backup.id | ||
|
|
||
| policy = jsonencode({ | ||
| Version = "2012-10-17" | ||
| Statement = [ | ||
| { | ||
| Sid = "DenyInsecureTransport" | ||
| Effect = "Deny" | ||
| Principal = "*" | ||
| Action = "s3:*" | ||
| Resource = [ | ||
| aws_s3_bucket.mysql_backup.arn, | ||
| "${aws_s3_bucket.mysql_backup.arn}/*", | ||
| ] | ||
| Condition = { | ||
| Bool = { | ||
| "aws:SecureTransport" = "false" | ||
| } | ||
| } | ||
| }, | ||
| ] | ||
| }) | ||
| } | ||
|
|
||
| resource "aws_s3_bucket_server_side_encryption_configuration" "mysql_backup" { | ||
| bucket = aws_s3_bucket.mysql_backup.id | ||
|
|
||
| rule { | ||
| apply_server_side_encryption_by_default { | ||
| sse_algorithm = "AES256" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| resource "aws_s3_bucket_versioning" "mysql_backup" { | ||
| bucket = aws_s3_bucket.mysql_backup.id | ||
|
|
||
| versioning_configuration { | ||
| status = "Enabled" | ||
| } | ||
| } | ||
|
|
||
| resource "aws_s3_bucket_object_lock_configuration" "mysql_backup" { | ||
| bucket = aws_s3_bucket.mysql_backup.id | ||
|
|
||
| depends_on = [aws_s3_bucket_versioning.mysql_backup] | ||
|
|
||
| rule { | ||
| default_retention { | ||
| mode = "GOVERNANCE" | ||
| days = 14 | ||
| } | ||
| } | ||
| } | ||
|
|
||
| resource "aws_s3_bucket_lifecycle_configuration" "mysql_backup" { | ||
| bucket = aws_s3_bucket.mysql_backup.id | ||
|
|
||
| depends_on = [ | ||
| aws_s3_bucket_versioning.mysql_backup, | ||
| aws_s3_bucket_object_lock_configuration.mysql_backup, | ||
| ] | ||
|
|
||
| rule { | ||
| id = "expire-mysql-backups-after-14-days" | ||
| status = "Enabled" | ||
|
|
||
| filter {} | ||
|
|
||
| expiration { | ||
| days = 14 | ||
| } | ||
|
|
||
| noncurrent_version_expiration { | ||
| noncurrent_days = 1 | ||
| } | ||
|
|
||
| abort_incomplete_multipart_upload { | ||
| days_after_initiation = 1 | ||
| } | ||
| } | ||
|
|
||
| rule { | ||
| id = "remove-expired-delete-markers" | ||
| status = "Enabled" | ||
|
|
||
| filter {} | ||
|
|
||
| expiration { | ||
| expired_object_delete_marker = true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # S3 Gateway Endpoint에는 별도 시간당 또는 데이터 처리 비용이 없습니다. | ||
| # 접근 권한은 Terraform에 선언하지 않고 수동으로 관리하는 IAM 정책에서 제한합니다. | ||
| data "aws_route_table" "db_ec2" { | ||
| subnet_id = var.db_ec2_subnet_id | ||
| } | ||
|
|
||
| resource "aws_vpc_endpoint" "mysql_backup_s3" { | ||
| vpc_id = data.aws_vpc.default.id | ||
| service_name = "com.amazonaws.ap-northeast-2.s3" | ||
| vpc_endpoint_type = "Gateway" | ||
| route_table_ids = [data.aws_route_table.db_ec2.id] | ||
|
|
||
| policy = jsonencode({ | ||
| Version = "2012-10-17" | ||
| Statement = [ | ||
| { | ||
| Sid = "AllowBackupBucketMetadataAccess" | ||
| Effect = "Allow" | ||
| Principal = "*" | ||
| Action = [ | ||
| "s3:GetBucketLocation", | ||
| "s3:ListBucket", | ||
| "s3:ListBucketMultipartUploads", | ||
| "s3:ListBucketVersions", | ||
| ] | ||
| Resource = aws_s3_bucket.mysql_backup.arn | ||
| }, | ||
| { | ||
| Sid = "AllowBackupObjectAccess" | ||
| Effect = "Allow" | ||
| Principal = "*" | ||
| Action = [ | ||
| "s3:AbortMultipartUpload", | ||
| "s3:GetObject", | ||
| "s3:GetObjectVersion", | ||
| "s3:ListMultipartUploadParts", | ||
| "s3:PutObject", | ||
| ] | ||
| Resource = "${aws_s3_bucket.mysql_backup.arn}/*" | ||
| }, | ||
| ] | ||
| }) | ||
|
|
||
| tags = { | ||
| Name = "solid-connection-prod-mysql-backup-s3" | ||
| } | ||
| } | ||
This file contains hidden or 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,9 @@ | ||
| output "mysql_backup_bucket_name" { | ||
| description = "Prod MySQL 백업 S3 버킷 이름" | ||
| value = aws_s3_bucket.mysql_backup.bucket | ||
| } | ||
|
|
||
| output "mysql_backup_s3_vpc_endpoint_id" { | ||
| description = "Prod MySQL 백업용 S3 Gateway VPC Endpoint ID" | ||
| value = aws_vpc_endpoint.mysql_backup_s3.id | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.