diff --git a/README.md b/README.md
index 4ceba773..0fd6e03a 100644
--- a/README.md
+++ b/README.md
@@ -191,6 +191,7 @@ No modules.
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_canonical_user_id.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/canonical_user_id) | data source |
| [aws_iam_policy_document.access_log_delivery](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
+| [aws_iam_policy_document.cloudtrail_log_delivery](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.combined](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.deny_incorrect_encryption_headers](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.deny_incorrect_kms_key_sse](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
@@ -221,6 +222,7 @@ No modules.
| [analytics\_source\_bucket\_arn](#input\_analytics\_source\_bucket\_arn) | The analytics source bucket ARN. | `string` | `null` | no |
| [attach\_access\_log\_delivery\_policy](#input\_attach\_access\_log\_delivery\_policy) | Controls if S3 bucket should have S3 access log delivery policy attached | `bool` | `false` | no |
| [attach\_analytics\_destination\_policy](#input\_attach\_analytics\_destination\_policy) | Controls if S3 bucket should have bucket analytics destination policy attached. | `bool` | `false` | no |
+| [attach\_cloudtrail\_log\_delivery\_policy](#input\_attach\_cloudtrail\_log\_delivery\_policy) | Controls if S3 bucket should have CloudTrail log delivery policy attached | `bool` | `false` | no |
| [attach\_deny\_incorrect\_encryption\_headers](#input\_attach\_deny\_incorrect\_encryption\_headers) | Controls if S3 bucket should deny incorrect encryption headers policy attached. | `bool` | `false` | no |
| [attach\_deny\_incorrect\_kms\_key\_sse](#input\_attach\_deny\_incorrect\_kms\_key\_sse) | Controls if S3 bucket policy should deny usage of incorrect KMS key SSE. | `bool` | `false` | no |
| [attach\_deny\_insecure\_transport\_policy](#input\_attach\_deny\_insecure\_transport\_policy) | Controls if S3 bucket should have deny non-SSL transport policy attached | `bool` | `false` | no |
diff --git a/examples/complete/main.tf b/examples/complete/main.tf
index 91dc2d7e..c6588782 100644
--- a/examples/complete/main.tf
+++ b/examples/complete/main.tf
@@ -73,6 +73,7 @@ module "log_bucket" {
attach_elb_log_delivery_policy = true
attach_lb_log_delivery_policy = true
attach_access_log_delivery_policy = true
+ attach_cloudtrail_log_delivery_policy = true
attach_deny_insecure_transport_policy = true
attach_require_latest_tls_policy = true
attach_waf_log_delivery_policy = true
diff --git a/main.tf b/main.tf
index 10f8fdb5..e1c57510 100644
--- a/main.tf
+++ b/main.tf
@@ -12,7 +12,7 @@ locals {
create_bucket_acl = (var.acl != null && var.acl != "null") || length(local.grants) > 0
- attach_policy = var.attach_require_latest_tls_policy || var.attach_access_log_delivery_policy || var.attach_elb_log_delivery_policy || var.attach_lb_log_delivery_policy || var.attach_deny_insecure_transport_policy || var.attach_inventory_destination_policy || var.attach_deny_incorrect_encryption_headers || var.attach_deny_incorrect_kms_key_sse || var.attach_deny_unencrypted_object_uploads || var.attach_deny_ssec_encrypted_object_uploads || var.attach_policy || var.attach_waf_log_delivery_policy
+ attach_policy = var.attach_require_latest_tls_policy || var.attach_access_log_delivery_policy || var.attach_elb_log_delivery_policy || var.attach_lb_log_delivery_policy || var.attach_cloudtrail_log_delivery_policy || var.attach_deny_insecure_transport_policy || var.attach_inventory_destination_policy || var.attach_deny_incorrect_encryption_headers || var.attach_deny_incorrect_kms_key_sse || var.attach_deny_unencrypted_object_uploads || var.attach_deny_ssec_encrypted_object_uploads || var.attach_policy || var.attach_waf_log_delivery_policy
# Variables with type `any` should be jsonencode()'d when value is coming from Terragrunt
grants = try(jsondecode(var.grant), var.grant)
@@ -569,6 +569,7 @@ data "aws_iam_policy_document" "combined" {
var.attach_elb_log_delivery_policy ? data.aws_iam_policy_document.elb_log_delivery[0].json : "",
var.attach_lb_log_delivery_policy ? data.aws_iam_policy_document.lb_log_delivery[0].json : "",
var.attach_access_log_delivery_policy ? data.aws_iam_policy_document.access_log_delivery[0].json : "",
+ var.attach_cloudtrail_log_delivery_policy ? data.aws_iam_policy_document.cloudtrail_log_delivery[0].json : "",
var.attach_require_latest_tls_policy ? data.aws_iam_policy_document.require_latest_tls[0].json : "",
var.attach_deny_insecure_transport_policy ? data.aws_iam_policy_document.deny_insecure_transport[0].json : "",
var.attach_deny_unencrypted_object_uploads ? data.aws_iam_policy_document.deny_unencrypted_object_uploads[0].json : "",
@@ -667,7 +668,7 @@ data "aws_iam_policy_document" "lb_log_delivery" {
count = local.create_bucket && var.attach_lb_log_delivery_policy && !var.is_directory_bucket ? 1 : 0
statement {
- sid = "AWSLogDeliveryWrite"
+ sid = "AlbNlbLogDeliveryWrite"
principals {
type = "Service"
@@ -702,7 +703,7 @@ data "aws_iam_policy_document" "lb_log_delivery" {
}
statement {
- sid = "AWSLogDeliveryAclCheck"
+ sid = "AlbNlbLogDeliveryAclCheck"
effect = "Allow"
@@ -822,7 +823,7 @@ data "aws_iam_policy_document" "waf_log_delivery" {
count = local.create_bucket && var.attach_waf_log_delivery_policy && !var.is_directory_bucket ? 1 : 0
statement {
- sid = "AWSLogDeliveryWrite"
+ sid = "WafLogDeliveryWrite"
effect = "Allow"
@@ -859,7 +860,7 @@ data "aws_iam_policy_document" "waf_log_delivery" {
}
statement {
- sid = "AWSLogDeliveryAclCheck"
+ sid = "WafLogDeliveryAclCheck"
effect = "Allow"
@@ -890,6 +891,46 @@ data "aws_iam_policy_document" "waf_log_delivery" {
}
}
+# CloudTrail
+data "aws_iam_policy_document" "cloudtrail_log_delivery" {
+ count = local.create_bucket && var.attach_cloudtrail_log_delivery_policy && !var.is_directory_bucket ? 1 : 0
+
+ statement {
+ sid = "AWSCloudTrailAclCheck"
+ principals {
+ type = "Service"
+ identifiers = ["cloudtrail.amazonaws.com"]
+ }
+ actions = [
+ "s3:GetBucketAcl",
+ ]
+ resources = [
+ aws_s3_bucket.this[0].arn,
+ ]
+ }
+
+ statement {
+ sid = "AWSCloudTrailWrite"
+ principals {
+ type = "Service"
+ identifiers = ["cloudtrail.amazonaws.com"]
+ }
+ actions = [
+ "s3:PutObject",
+ ]
+ resources = [
+ "${aws_s3_bucket.this[0].arn}/AWSLogs/*",
+ ]
+ condition {
+ test = "StringEquals"
+ variable = "s3:x-amz-acl"
+ values = [
+ "bucket-owner-full-control",
+ ]
+ }
+ }
+}
+
data "aws_iam_policy_document" "deny_insecure_transport" {
count = local.create_bucket && var.attach_deny_insecure_transport_policy && !var.is_directory_bucket ? 1 : 0
diff --git a/variables.tf b/variables.tf
index 86e03e2a..4652acff 100644
--- a/variables.tf
+++ b/variables.tf
@@ -22,6 +22,12 @@ variable "attach_access_log_delivery_policy" {
default = false
}
+variable "attach_cloudtrail_log_delivery_policy" {
+ description = "Controls if S3 bucket should have CloudTrail log delivery policy attached"
+ type = bool
+ default = false
+}
+
variable "attach_deny_insecure_transport_policy" {
description = "Controls if S3 bucket should have deny non-SSL transport policy attached"
type = bool
diff --git a/wrappers/main.tf b/wrappers/main.tf
index c38ab67d..e1a39316 100644
--- a/wrappers/main.tf
+++ b/wrappers/main.tf
@@ -15,6 +15,7 @@ module "wrapper" {
analytics_source_bucket_arn = try(each.value.analytics_source_bucket_arn, var.defaults.analytics_source_bucket_arn, null)
attach_access_log_delivery_policy = try(each.value.attach_access_log_delivery_policy, var.defaults.attach_access_log_delivery_policy, false)
attach_analytics_destination_policy = try(each.value.attach_analytics_destination_policy, var.defaults.attach_analytics_destination_policy, false)
+ attach_cloudtrail_log_delivery_policy = try(each.value.attach_cloudtrail_log_delivery_policy, var.defaults.attach_cloudtrail_log_delivery_policy, false)
attach_deny_incorrect_encryption_headers = try(each.value.attach_deny_incorrect_encryption_headers, var.defaults.attach_deny_incorrect_encryption_headers, false)
attach_deny_incorrect_kms_key_sse = try(each.value.attach_deny_incorrect_kms_key_sse, var.defaults.attach_deny_incorrect_kms_key_sse, false)
attach_deny_insecure_transport_policy = try(each.value.attach_deny_insecure_transport_policy, var.defaults.attach_deny_insecure_transport_policy, false)