-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmalware.tf
More file actions
55 lines (44 loc) · 2 KB
/
Copy pathmalware.tf
File metadata and controls
55 lines (44 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
resource "aws_iam_role" "malware_scanning" {
for_each = var.malware_scanning.enabled ? toset(["this"]) : toset([])
# bucket_name can be up to 63 characters, so use a truncated prefix and let
# AWS append a unique suffix to stay within the 64-character role name limit.
name_prefix = substr("${local.bucket_name}-scan-", 0, 38)
description = "Role for GuardDuty malware protection of bucket ${local.bucket_name}"
path = "/service-role/"
assume_role_policy = jsonencode(yamldecode(templatefile("${path.module}/templates/malware-scan-trust.yaml.tftpl", {
account = data.aws_caller_identity.identity.account_id
partition = data.aws_partition.current.partition
region = data.aws_region.current.region
})))
tags = var.tags
}
resource "aws_iam_role_policy" "malware_scanning" {
for_each = var.malware_scanning.enabled ? toset(["this"]) : toset([])
# bucket_name can be up to 63 characters, so use a truncated prefix and let
# AWS append a unique suffix to stay within the 64-character role name limit.
name_prefix = substr("${local.bucket_name}-scan-", 0, 38)
role = aws_iam_role.malware_scanning["this"].id
policy = jsonencode(yamldecode(templatefile("${path.module}/templates/malware-scan-policy.yaml.tftpl", {
account = data.aws_caller_identity.identity.account_id
bucket = local.bucket_name
kms_key_arn = local.kms_key_arn
partition = data.aws_partition.current.partition
region = data.aws_region.current.region
})))
}
resource "aws_guardduty_malware_protection_plan" "this" {
for_each = var.malware_scanning.enabled ? toset(["this"]) : toset([])
role = aws_iam_role.malware_scanning["this"].arn
protected_resource {
s3_bucket {
bucket_name = aws_s3_bucket.this.id
object_prefixes = length(var.malware_scanning.object_prefixes) > 0 ? var.malware_scanning.object_prefixes : null
}
}
actions {
tagging {
status = var.malware_scanning.tag_objects ? "ENABLED" : "DISABLED"
}
}
tags = var.tags
}