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 6, 2022
1 parent ccf33e2 commit b5bc513
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
4 changes: 4 additions & 0 deletions cloudtrail/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,12 @@ No modules.
| [aws_iam_policy.cloudtrail_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
| [aws_iam_role.cloudtrail](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
| [aws_s3_bucket.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
| [aws_s3_bucket_acl.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_acl) | resource |
| [aws_s3_bucket_logging.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_logging) | 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.policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_policy) | resource |
| [aws_s3_bucket_public_access_block.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | resource |
| [aws_s3_bucket_server_side_encryption_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_server_side_encryption_configuration) | resource |
| [aws_sns_topic.cloudtrail](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic) | resource |
| [aws_sns_topic_policy.cloudtrail](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_policy) | resource |
| [aws_sns_topic_subscription.cloudtrail_sqs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_subscription) | resource |
Expand Down
39 changes: 28 additions & 11 deletions cloudtrail/s3.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,43 @@ resource "aws_s3_bucket" "this" {
acl = "private"
force_destroy = false

logging {
target_bucket = var.access_log_bucket
target_prefix = format("%s/%s/", var.access_log_bucket_prefix, local.bucket_name)
}

tags = merge(
local.base_tags,
var.tags,
{ "Name" = local.name },
)
}

server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
kms_master_key_id = var.kms_key_arn
sse_algorithm = "aws:kms"
}
resource "aws_s3_bucket_server_side_encryption_configuration" "this" {
bucket = aws_s3_bucket.this.id
rule {
apply_server_side_encryption_by_default {
kms_master_key_id = var.kms_key_arn
sse_algorithm = "aws:kms"
}
}
}

resource "aws_s3_bucket_logging" "this" {
bucket = aws_s3_bucket.this.id
target_bucket = var.access_log_bucket
target_prefix = format("%s/%s/", var.access_log_bucket_prefix, local.bucket_name)
}

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

resource "aws_s3_bucket_ownership_controls" "this" {
bucket = aws_s3_bucket.this.id

rule {
object_ownership = "BucketOwnerEnforced"
}
}

#---
# bucket policy (apply also encryption key usage here?)
# deny unencrypted uploads policy statement removed for default encryption
Expand Down Expand Up @@ -86,3 +102,4 @@ resource "null_resource" "policy_delay" {
command = "sleep 180"
}
}

0 comments on commit b5bc513

Please sign in to comment.