generated from cn-terraform/terraform-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial commit * Update variables.tf * Update variables.tf * First version of the module * First version of the module
- Loading branch information
Showing
12 changed files
with
205 additions
and
52 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
examples/disabled/.terraform.lock.hcl β examples/test/.terraform.lock.hcl
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module "logs_bucket" { | ||
source = "../../" | ||
|
||
name_prefix = "test" | ||
aws_principals_identifiers = ["test-user-arn"] | ||
block_s3_bucket_public_access = true | ||
enable_s3_bucket_server_side_encryption = true | ||
s3_bucket_server_side_encryption_sse_algorithm = "aws:kms" | ||
s3_bucket_server_side_encryption_key = "aws/s3" | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#------------------------------------------------------------------------------ | ||
# S3 BUCKET - For access logs | ||
#------------------------------------------------------------------------------ | ||
resource "random_string" "random" { | ||
length = 7 | ||
lower = true | ||
number = false | ||
upper = false | ||
special = false | ||
keepers = { | ||
name_prefix = var.name_prefix | ||
} | ||
} | ||
|
||
resource "aws_s3_bucket" "logs" { | ||
bucket = lower("${random_string.random.keepers.name_prefix}-logs-${random_string.random.result}") | ||
tags = merge( | ||
var.tags, | ||
{ | ||
Name = lower("${random_string.random.keepers.name_prefix}-logs-${random_string.random.result}") | ||
}, | ||
) | ||
} | ||
|
||
resource "aws_s3_bucket_acl" "logs" { | ||
bucket = aws_s3_bucket.logs.id | ||
acl = "log-delivery-write" | ||
} | ||
|
||
resource "aws_s3_bucket_server_side_encryption_configuration" "logs" { | ||
count = var.enable_s3_bucket_server_side_encryption ? 1 : 0 | ||
|
||
bucket = aws_s3_bucket.logs.id | ||
|
||
rule { | ||
apply_server_side_encryption_by_default { | ||
sse_algorithm = var.s3_bucket_server_side_encryption_sse_algorithm | ||
kms_master_key_id = var.s3_bucket_server_side_encryption_sse_algorithm == "aws:kms" ? var.s3_bucket_server_side_encryption_key : null | ||
|
||
} | ||
} | ||
} | ||
|
||
#------------------------------------------------------------------------------ | ||
# IAM POLICY DOCUMENT - For access logs to the S3 bucket | ||
#------------------------------------------------------------------------------ | ||
data "aws_iam_policy_document" "logs_access_policy_document" { | ||
statement { | ||
effect = "Allow" | ||
|
||
principals { | ||
type = "AWS" | ||
identifiers = var.aws_principals_identifiers | ||
} | ||
|
||
actions = [ | ||
"s3:PutObject", | ||
] | ||
|
||
resources = [ | ||
"${aws_s3_bucket.logs.arn}/*", | ||
] | ||
} | ||
} | ||
|
||
#------------------------------------------------------------------------------ | ||
# IAM POLICY - For access logs to the s3 bucket | ||
#------------------------------------------------------------------------------ | ||
resource "aws_s3_bucket_policy" "logs_access_policy" { | ||
bucket = aws_s3_bucket.logs.id | ||
policy = data.aws_iam_policy_document.logs_access_policy_document.json | ||
} | ||
|
||
#------------------------------------------------------------------------------ | ||
# S3 bucket block public access | ||
#------------------------------------------------------------------------------ | ||
resource "aws_s3_bucket_public_access_block" "logs_block_public_access" { | ||
count = var.block_s3_bucket_public_access ? 1 : 0 | ||
|
||
bucket = aws_s3_bucket.logs.id | ||
|
||
block_public_acls = true | ||
block_public_policy = true | ||
ignore_public_acls = true | ||
restrict_public_buckets = true | ||
|
||
depends_on = [aws_s3_bucket_policy.logs_access_policy] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#------------------------------------------------------------------------------ | ||
# S3 Bucket | ||
#------------------------------------------------------------------------------ | ||
output "lb_logs_s3_bucket_id" { | ||
description = "LB Logging S3 Bucket ID" | ||
value = aws_s3_bucket.logs.id | ||
} | ||
|
||
output "lb_logs_s3_bucket_arn" { | ||
description = "LB Logging S3 Bucket ARN" | ||
value = aws_s3_bucket.logs.arn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
558e237
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π° Infracost estimate: monthly cost will not change
Infracost output
558e237
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π° Infracost estimate: monthly cost will not change
Infracost output