Skip to content

Commit

Permalink
refactor for aws provider v4
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed May 7, 2022
1 parent 1764ba5 commit 31c7ad8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
3 changes: 3 additions & 0 deletions s3-access-logs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ No modules.
| Name | Type |
|------|------|
| [aws_s3_bucket.logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
| [aws_s3_bucket_acl.logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_acl) | resource |
| [aws_s3_bucket_object.logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_object) | resource |
| [aws_s3_bucket_ownership_controls.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_ownership_controls) | resource |
| [aws_s3_bucket_policy.logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_policy) | resource |
| [aws_s3_bucket_public_access_block.logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | resource |
| [aws_s3_bucket_server_side_encryption_configuration.logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_server_side_encryption_configuration) | resource |
| [aws_s3_bucket_versioning.logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_versioning) | resource |
| [null_resource.policy_delay](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [aws_arn.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/arn) | data source |
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
Expand Down
63 changes: 36 additions & 27 deletions s3-access-logs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,7 @@ locals {
resource "aws_s3_bucket" "logs" {
bucket = local.bucket_name
# acl = "log-delivery-write"
acl = "private"

# uses aws/kms key so log delivery works properly
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "aws:kms"
}
}
}

versioning {
enabled = false
}
# acl = "private"

lifecycle {
prevent_destroy = true
Expand Down Expand Up @@ -108,6 +95,41 @@ resource "aws_s3_bucket_public_access_block" "logs" {
restrict_public_buckets = true
}

resource "aws_s3_bucket_versioning" "logs" {
bucket = aws_s3_bucket.logs.id
versioning_configuration {
status = "Disabled"
}
}

#---
# set ownership controls
# see documentation:
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_ownership_controls
# https://docs.aws.amazon.com/AmazonS3/latest/userguide/about-object-ownership.html

resource "aws_s3_bucket_ownership_controls" "this" {
bucket = aws_s3_bucket.logs.id
rule {
object_ownership = "BucketOwnerEnforced"
}
}

resource "aws_s3_bucket_server_side_encryption_configuration" "logs" {
bucket = aws_s3_bucket.logs.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "aws:kms"
}
}
}

resource "aws_s3_bucket_acl" "logs" {
# count = 0
bucket = aws_s3_bucket.logs.id
acl = "private"
}

#---
# create "directories"
#---
Expand All @@ -134,16 +156,3 @@ resource "null_resource" "policy_delay" {
command = "sleep 120"
}
}

#---
# set ownership controls
# see documentation:
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_ownership_controls
# https://docs.aws.amazon.com/AmazonS3/latest/userguide/about-object-ownership.html
resource "aws_s3_bucket_ownership_controls" "this" {
bucket = aws_s3_bucket.logs.id

rule {
object_ownership = "BucketOwnerEnforced"
}
}

0 comments on commit 31c7ad8

Please sign in to comment.