Skip to content

Commit

Permalink
Merge pull request #306 from trussworks/policy-example
Browse files Browse the repository at this point in the history
NT: adds arn as output and custom bucket policy example
  • Loading branch information
nyanbinaryneko authored Mar 10, 2023
2 parents 4df548c + dda43d3 commit d44df91
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ No modules.
| Name | Description |
|------|-------------|
| aws\_logs\_bucket | ID of the S3 bucket containing AWS logs. |
| bucket\_arn | ARN of the S3 logs bucket |
| configs\_logs\_path | S3 path for Config logs. |
| elb\_logs\_path | S3 path for ELB logs. |
| redshift\_logs\_path | S3 path for RedShift logs. |
Expand Down
37 changes: 37 additions & 0 deletions examples/custom_bucket_policy/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module "aws_logs" {
source = "../../"

s3_bucket_name = var.test_name

force_destroy = var.force_destroy
tags = var.tags
}

data "aws_iam_policy_document" "updated_logs_bucket_policy" {
source_policy_documents = [module.aws_logs.s3_bucket_policy.json]
statement {
sid = "Allow vpc endpoint"
actions = ["s3:*"]
effect = "Allow"
condition {
test = "StringEquals"
variable = "aws:SourceVpce"
values = ["vpce-0123567"]
}

resources = [
module.aws_logs.bucket_arn,
"${module.aws_logs.bucket_arn}/*"
]

principals {
type = "*"
identifiers = ["*"]
}
}

}
resource "aws_s3_bucket_policy" "logs_updated_bucket_policy" {
bucket = module.logs.aws_logs_bucket
policy = data.updated_logs_bucket_policy.json
}
16 changes: 16 additions & 0 deletions examples/custom_bucket_policy/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
variable "test_name" {
type = string
}

variable "region" {
type = string
}

variable "force_destroy" {
type = bool
}

variable "tags" {
type = map(string)
default = {}
}
5 changes: 5 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ output "s3_bucket_policy" {
description = "S3 bucket policy"
value = data.aws_iam_policy_document.main
}

output "bucket_arn" {
description = "ARN of the S3 logs bucket"
value = aws_s3_bucket.aws_logs.arn
}

0 comments on commit d44df91

Please sign in to comment.