From 023e94e9a537539c7b119e6cf35c82b1da4dd019 Mon Sep 17 00:00:00 2001 From: keitakn Date: Sun, 4 Apr 2021 23:57:30 +0900 Subject: [PATCH] =?UTF-8?q?:sparkles:=20#12=20=E4=B8=80=E6=99=82=E7=9A=84?= =?UTF-8?q?=E3=81=AB=E7=94=BB=E5=83=8F=E3=82=92=E4=BF=9D=E5=AD=98=E3=81=99?= =?UTF-8?q?=E3=82=8B=E7=94=A8=E3=81=AES3=E3=83=90=E3=82=B1=E3=83=83?= =?UTF-8?q?=E3=83=88=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/aws/images/main.tf | 22 +++++++++++++++++++ modules/aws/images/outputs.tf | 4 ++++ modules/aws/images/variables.tf | 4 ++++ .../aws/environments/prod/11-images/main.tf | 1 + .../environments/prod/11-images/outputs.tf | 4 ++++ .../environments/prod/11-images/variables.tf | 1 + 6 files changed, 36 insertions(+) diff --git a/modules/aws/images/main.tf b/modules/aws/images/main.tf index 712acac..597cd75 100644 --- a/modules/aws/images/main.tf +++ b/modules/aws/images/main.tf @@ -1,3 +1,25 @@ +resource "aws_s3_bucket" "upload_images_bucket" { + bucket = var.upload_images_bucket_name + acl = "private" + + force_destroy = true + + versioning { + enabled = true + } + + lifecycle_rule { + enabled = true + // 失効した削除マーカーまたは不完全なマルチパートアップロードを削除する + abort_incomplete_multipart_upload_days = 7 + + // 古いバージョンは30日で削除 + noncurrent_version_expiration { + days = 30 + } + } +} + resource "aws_s3_bucket" "lgtm_images_bucket" { bucket = var.lgtm_images_bucket_name acl = "private" diff --git a/modules/aws/images/outputs.tf b/modules/aws/images/outputs.tf index e2bbd5b..8e5340d 100644 --- a/modules/aws/images/outputs.tf +++ b/modules/aws/images/outputs.tf @@ -1,3 +1,7 @@ +output "upload_images_bucket_name" { + value = aws_s3_bucket.upload_images_bucket.bucket +} + output "lgtm_images_bucket_name" { value = aws_s3_bucket.lgtm_images_bucket.bucket } diff --git a/modules/aws/images/variables.tf b/modules/aws/images/variables.tf index 6bf0193..3d95723 100644 --- a/modules/aws/images/variables.tf +++ b/modules/aws/images/variables.tf @@ -1,3 +1,7 @@ +variable "upload_images_bucket_name" { + type = string +} + variable "lgtm_images_bucket_name" { type = string } diff --git a/providers/aws/environments/prod/11-images/main.tf b/providers/aws/environments/prod/11-images/main.tf index 96637a9..19ad277 100644 --- a/providers/aws/environments/prod/11-images/main.tf +++ b/providers/aws/environments/prod/11-images/main.tf @@ -5,4 +5,5 @@ module "images" { lgtm_images_cdn_domain = local.lgtm_images_cdn_domain lgtm_images_cdn_acm_arn = local.lgtm_images_cdn_acm_arn main_host_zone = data.aws_route53_zone.main_host_zone.zone_id + upload_images_bucket_name = local.upload_images_bucket_name } diff --git a/providers/aws/environments/prod/11-images/outputs.tf b/providers/aws/environments/prod/11-images/outputs.tf index 096c3c3..280dbe5 100644 --- a/providers/aws/environments/prod/11-images/outputs.tf +++ b/providers/aws/environments/prod/11-images/outputs.tf @@ -1,3 +1,7 @@ +output "upload_images_bucket_name" { + value = module.images.upload_images_bucket_name +} + output "lgtm_images_bucket_name" { value = module.images.lgtm_images_bucket_name } diff --git a/providers/aws/environments/prod/11-images/variables.tf b/providers/aws/environments/prod/11-images/variables.tf index 5377d03..1ffc89c 100644 --- a/providers/aws/environments/prod/11-images/variables.tf +++ b/providers/aws/environments/prod/11-images/variables.tf @@ -6,6 +6,7 @@ locals { lgtm_images_cdn_domain = "${local.lgtm_images_cdn_sub_domain}.${var.main_domain_name}" lgtm_images_cdn_acm_arn = data.terraform_remote_state.acm.outputs.us_east_1_sub_domain_acm_arn main_host_zone = data.aws_route53_zone.main_host_zone + upload_images_bucket_name = "${local.env}-${local.name}-upload-images" } variable "main_domain_name" {