코드
resource "aws_s3_bucket" "test" {
bucket = "tf-test-hyeob-bucket"
tags = {
Name = "tf-test-hyeob"
Environment = "Dev"
}
}
resource "aws_s3_bucket_acl" "test" {
bucket = aws_s3_bucket.test.id
acl = "private"
}
resource "aws_s3_object" "object" {
for_each = fileset("uploads/", "*.html")
bucket = data.aws_s3_bucket.selected-bucket.bucket
key = each.value
source = "uploads/${each.value}"
content_type = "text/html"
etag = filemd5("uploads/${each.value}")
acl = "public-read"
}
resource "aws_s3_bucket_policy" "allow_access_from_another_account" {
bucket = aws_s3_bucket.test.id
policy = data.aws_iam_policy_document.allow_access_from_another_account.json
}
data "aws_iam_user" "test" {
user_name = var.user_id
}
data "aws_iam_policy_document" "allow_access_from_another_account" {
statement {
sid = "bucketPolicyTest"
principals {
type = "AWS"
identifiers = ["*"]
}
actions = [
"s3:GetObject",
"s3:ListBucket",
]
resources = [
aws_s3_bucket.test.arn,
"${aws_s3_bucket.test.arn}/*",
]
}
}
resource "aws_s3_bucket_versioning" "test" {
bucket = aws_s3_bucket.test.id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket" "log_bucket" {
bucket = "tf-test-hyeob-log-bucket"
}
resource "aws_s3_bucket_acl" "log_bucket_acl" {
bucket = aws_s3_bucket.log_bucket.id
acl = "log-delivery-write"
}
resource "aws_s3_bucket_logging" "test" {
bucket = aws_s3_bucket.test.id
target_bucket = aws_s3_bucket.log_bucket.id
target_prefix = "log/"
}
resource "aws_s3_bucket_website_configuration" "test" {
bucket = aws_s3_bucket.test.id
index_document {
suffix = "index.html"
}
error_document {
key = "error.html"
}
}
resource "aws_s3_bucket_lifecycle_configuration" "test" {
bucket = aws_s3_bucket.test.id
rule {
id = "log"
expiration {
days = 90
}
filter {
and {
prefix = "log/"
tags = {
rule = "log"
autoclean = "true"
}
}
}
status = "Enabled"
transition {
days = 30
storage_class = "STANDARD_IA"
}
transition {
days = 60
storage_class = "GLACIER"
}
}
rule {
id = "tmp"
filter {
prefix = "tmp/"
}
expiration {
date = "2023-01-13T00:00:00Z"
}
status = "Enabled"
}
}