Skip to content

Commit

Permalink
Create main.tf
Browse files Browse the repository at this point in the history
  • Loading branch information
anujdevopslearn authored Apr 25, 2024
1 parent 9c8bb6c commit 39e1d4a
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions s3_terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# main.tf
resource "aws_s3_bucket" "example" {
bucket = "my-tf-example-bucket"
tags = {
Name = "MyS3Bucket"
Environment = "Production"
}
}
resource "aws_s3_bucket_acl" "example" {
bucket = aws_s3_bucket.example.id
acl = "private"
}
resource "aws_s3_bucket" "log_bucket" {
bucket = "my-tf-log-bucket"
tags = {
Name = "MyLogBucket"
Environment = "Production"
}
}
resource "aws_s3_bucket_acl" "log_bucket_acl" {
bucket = aws_s3_bucket.log_bucket.id
acl = "log-delivery-write"
}
resource "aws_s3_bucket_logging" "example" {
bucket = aws_s3_bucket.example.id
target_bucket = aws_s3_bucket.log_bucket.id
target_prefix = "log/"
}

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
}
data "aws_iam_policy_document" "allow_access_from_another_account" {
statement {
principals {
type = "AWS"
identifiers = ["123456789012"]
}
actions = [
"s3:GetObject",
"s3:ListBucket",
]
resources = [
aws_s3_bucket.example.arn,
"${aws_s3_bucket.example.arn}/*",
]
}
}

0 comments on commit 39e1d4a

Please sign in to comment.