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 = "public-read-write"
}
resource "aws_s3_bucket_policy" "allow_access_from_another_account" {
bucket = aws_s3_bucket.example.id
policy = data.aws_iam_policy_document.allow_access_from_another_account.json
}
resource "aws_s3_bucket_versioning" "test" {
bucket = aws_s3_bucket.test.id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket_cors_configuration" "test" {
bucket = aws_s3_bucket.test.id
cors_rule {
allowed_headers = ["*"]
allowed_methods = ["PUT", "POST"]
allowed_origins = ["https://s3-website-test.hashicorp.com"]
expose_headers = ["ETag"]
max_age_seconds = 3000
}
cors_rule {
allowed_methods = ["GET"]
allowed_origins = ["*"]
}
}
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"
}
routing_rule {
condition {
key_prefix_equals = "docs/"
}
redirect {
replace_key_prefix_with = "documents/"
}
}
}
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"
}
}