diff --git a/README.md b/README.md
index 54a0a415..043811cb 100644
--- a/README.md
+++ b/README.md
@@ -170,6 +170,7 @@ No modules.
| [aws_iam_policy_document.deny_insecure_transport](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.deny_unencrypted_object_uploads](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.elb_log_delivery](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
+| [aws_iam_policy_document.inspector_findings_delivery_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.inventory_and_analytics_destination_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.lb_log_delivery](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.require_latest_tls](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
@@ -198,6 +199,7 @@ No modules.
| [attach\_elb\_log\_delivery\_policy](#input\_attach\_elb\_log\_delivery\_policy) | Controls if S3 bucket should have ELB log delivery policy attached | `bool` | `false` | no |
| [attach\_inventory\_destination\_policy](#input\_attach\_inventory\_destination\_policy) | Controls if S3 bucket should have bucket inventory destination policy attached. | `bool` | `false` | no |
| [attach\_lb\_log\_delivery\_policy](#input\_attach\_lb\_log\_delivery\_policy) | Controls if S3 bucket should have ALB/NLB log delivery policy attached | `bool` | `false` | no |
+| [attach\_inspector\_findings\_delivery\_policy](#input\_attach\_inspector\_findings\_delivery\_policy) | Controls if S3 bucket should have Inspector findings delivery policy attached | `bool` | `false` | no |
| [attach\_policy](#input\_attach\_policy) | Controls if S3 bucket should have bucket policy attached (set to `true` to use value of `policy` as bucket policy) | `bool` | `false` | no |
| [attach\_public\_policy](#input\_attach\_public\_policy) | Controls if a user defined public bucket policy will be attached (set to `false` to allow upstream to apply defaults to the bucket) | `bool` | `true` | no |
| [attach\_require\_latest\_tls\_policy](#input\_attach\_require\_latest\_tls\_policy) | Controls if S3 bucket should require the latest version of TLS | `bool` | `false` | no |
diff --git a/examples/s3-inventory/main.tf b/examples/s3-inventory/main.tf
index ddbcf739..300f191c 100644
--- a/examples/s3-inventory/main.tf
+++ b/examples/s3-inventory/main.tf
@@ -93,6 +93,7 @@ resource "random_pet" "this" {
# https://docs.aws.amazon.com/AmazonS3/latest/userguide/configure-inventory.html#configure-inventory-kms-key-policy
module "kms" {
source = "terraform-aws-modules/kms/aws"
+ version = "~> 2.0"
description = "Key example for Inventory S3 destination encyrption"
deletion_window_in_days = 7
diff --git a/main.tf b/main.tf
index fdea2a29..33ebb983 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_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_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_inspector_findings_delivery_policy || var.attach_policy
# Variables with type `any` should be jsonencode()'d when value is coming from Terragrunt
grants = try(jsondecode(var.grant), var.grant)
@@ -562,6 +562,7 @@ data "aws_iam_policy_document" "combined" {
var.attach_deny_incorrect_kms_key_sse ? data.aws_iam_policy_document.deny_incorrect_kms_key_sse[0].json : "",
var.attach_deny_incorrect_encryption_headers ? data.aws_iam_policy_document.deny_incorrect_encryption_headers[0].json : "",
var.attach_inventory_destination_policy || var.attach_analytics_destination_policy ? data.aws_iam_policy_document.inventory_and_analytics_destination_policy[0].json : "",
+ var.attach_inspector_findings_delivery_policy ? data.aws_iam_policy_document.inspector_findings_delivery_policy[0].json : "",
var.attach_policy ? var.policy : ""
])
}
@@ -909,6 +910,44 @@ data "aws_iam_policy_document" "deny_unencrypted_object_uploads" {
}
}
+data "aws_iam_policy_document" "inspector_findings_delivery_policy" {
+ count = local.create_bucket && var.attach_inspector_findings_delivery_policy ? 1 : 0
+
+ statement {
+ sid = "allow-inspector"
+ effect = "Allow"
+
+ actions = [
+ "s3:PutObject",
+ "s3:PutObjectAcl",
+ "s3:AbortMultipartUpload"
+ ]
+
+ resources = ["${aws_s3_bucket.this[0].arn}/*"]
+
+ principals {
+ type = "Service"
+ identifiers = ["inspector2.amazonaws.com"]
+ }
+
+ condition {
+ test = "StringEquals"
+ variable = "aws:SourceAccount"
+ values = [
+ data.aws_caller_identity.current.id
+ ]
+ }
+ condition {
+ test = "ArnLike"
+ variable = "aws:SourceArn"
+ values = [
+ format("%s%s%s", "arn:aws:inspector2:Region:", data.aws_caller_identity.current.id, ":report/*")
+ ]
+ }
+ }
+}
+
+
resource "aws_s3_bucket_public_access_block" "this" {
count = local.create_bucket && var.attach_public_policy ? 1 : 0
diff --git a/variables.tf b/variables.tf
index 95e0cb49..dbe39d71 100644
--- a/variables.tf
+++ b/variables.tf
@@ -82,6 +82,12 @@ variable "attach_deny_unencrypted_object_uploads" {
default = false
}
+variable "attach_inspector_findings_delivery_policy" {
+ description = "Controls if S3 bucket should have Inspector findings delivery policy attached"
+ type = bool
+ default = false
+}
+
variable "bucket" {
description = "(Optional, Forces new resource) The name of the bucket. If omitted, Terraform will assign a random, unique name."
type = string