Skip to content

Commit b59652e

Browse files
committed
add guardduty for every region
1 parent 9e917ae commit b59652e

File tree

4 files changed

+65
-26
lines changed

4 files changed

+65
-26
lines changed

main.tf

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -335,24 +335,27 @@ module "config" {
335335

336336
#Module : GUARD DUTY
337337
module "guardduty" {
338-
source = "./modules/guardduty"
339-
name = "guardduty"
340-
application = var.application
341-
environment = var.environment
342-
managedby = var.managedby
343-
label_order = var.label_order
344-
enabled = var.enabled && var.guardduty_enable
345-
bucket_name = var.guardduty_s3_bucket_name
346-
ipset_format = "TXT"
347-
ipset_iplist = var.ipset_iplist
348-
threatintelset_activate = var.threatintelset_activate
349-
threatintelset_format = "TXT"
350-
threatintelset_iplist = var.threatintelset_iplist
351-
target_bucket = var.target_bucket
352-
target_prefix = var.target_prefix
353-
sse_algorithm = var.sse_algorithm
354-
tracing_mode = var.tracing_mode
355-
attach_tracing_policy = var.attach_tracing_policy
338+
source = "./modules/guardduty"
339+
name = "guardduty"
340+
application = var.application
341+
environment = var.environment
342+
managedby = var.managedby
343+
label_order = var.label_order
344+
enabled = var.enabled && var.guardduty_enable
345+
only_guardduty_enable = var.only_guardduty_enable
346+
ipset_location = var.ipset_location
347+
threatintelset_iplist_location = var.threatintelset_iplist_location
348+
bucket_name = var.guardduty_s3_bucket_name
349+
ipset_format = "TXT"
350+
ipset_iplist = var.ipset_iplist
351+
threatintelset_activate = var.threatintelset_activate
352+
threatintelset_format = "TXT"
353+
threatintelset_iplist = var.threatintelset_iplist
354+
target_bucket = var.target_bucket
355+
target_prefix = var.target_prefix
356+
sse_algorithm = var.sse_algorithm
357+
tracing_mode = var.tracing_mode
358+
attach_tracing_policy = var.attach_tracing_policy
356359

357360
is_guardduty_member = var.is_guardduty_member
358361
member_list = var.member_list

modules/guardduty/main.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module "labels" {
1616
}
1717

1818
resource "aws_s3_bucket" "bucket" {
19-
count = var.enabled ? 1 : 0
19+
count = var.enabled && var.only_guardduty_enable ? 1 : 0
2020
bucket = var.bucket_name
2121
acl = "private"
2222
force_destroy = true
@@ -46,7 +46,7 @@ resource "aws_guardduty_invite_accepter" "member_accepter" {
4646
}
4747

4848
resource "aws_s3_bucket_object" "ipset" {
49-
count = var.enabled ? 1 : 0
49+
count = var.enabled && var.only_guardduty_enable ? 1 : 0
5050
acl = "private"
5151
content = templatefile("${path.module}/templates/ipset.txt.tpl",
5252
{ ipset_iplist = var.ipset_iplist })
@@ -61,12 +61,12 @@ resource "aws_guardduty_ipset" "ipset" {
6161
activate = var.ipset_activate
6262
detector_id = join("", aws_guardduty_detector.detector.*.id)
6363
format = var.ipset_format
64-
location = "https://s3.amazonaws.com/${join("", aws_s3_bucket_object.ipset.*.bucket)}/${join("", aws_s3_bucket_object.ipset.*.key)}"
64+
location = var.ipset_location == "" ? "https://s3.amazonaws.com/${join("", aws_s3_bucket_object.ipset.*.bucket)}/${join("", aws_s3_bucket_object.ipset.*.key)}" : var.ipset_location
6565
name = format("%s-ipset", module.labels.id)
6666
}
6767

6868
resource "aws_s3_bucket_object" "threatintelset" {
69-
count = var.enabled ? 1 : 0
69+
count = var.enabled && var.only_guardduty_enable ? 1 : 0
7070
acl = "private"
7171
content = templatefile("${path.module}/templates/threatintelset.txt.tpl",
7272
{ threatintelset_iplist = var.threatintelset_iplist })
@@ -81,7 +81,7 @@ resource "aws_guardduty_threatintelset" "threatintelset" {
8181
activate = var.threatintelset_activate
8282
detector_id = join("", aws_guardduty_detector.detector.*.id)
8383
format = var.threatintelset_format
84-
location = "https://s3.amazonaws.com/${join("", aws_s3_bucket_object.threatintelset.*.bucket)}/${join("", aws_s3_bucket_object.threatintelset.*.key)}"
84+
location = var.threatintelset_iplist_location == "" ? "https://s3.amazonaws.com/${join("", aws_s3_bucket_object.threatintelset.*.bucket)}/${join("", aws_s3_bucket_object.threatintelset.*.key)}" : var.threatintelset_iplist_location
8585
name = format("%s-threat", module.labels.id)
8686
}
8787

@@ -98,7 +98,7 @@ resource "aws_guardduty_member" "member" {
9898
#Module : CLOUD WATCH EVENT RULE
9999
#Description : Event rule for cloud watch events.
100100
resource "aws_cloudwatch_event_rule" "default" {
101-
count = var.enabled ? 1 : 0
101+
count = var.enabled && var.only_guardduty_enable ? 1 : 0
102102
name = format("%s-er", module.labels.id)
103103
description = "Event rule for AWS Guarddduty."
104104
role_arn = var.rule_iam_role_arn
@@ -120,7 +120,7 @@ resource "aws_cloudwatch_event_rule" "default" {
120120
#Module : CLOUD WATCH EVENT TARGET
121121
#Description : Attaching event rule and lambda function to targets.
122122
resource "aws_cloudwatch_event_target" "default" {
123-
count = var.enabled ? 1 : 0
123+
count = var.enabled && var.only_guardduty_enable ? 1 : 0
124124
rule = join("", aws_cloudwatch_event_rule.default.*.name)
125125
target_id = "Guardduty"
126126
arn = module.slack-lambda.arn # ARN of the Lambda Function, write after including lambda function
@@ -136,7 +136,7 @@ module "slack-lambda" {
136136
environment = var.environment
137137
label_order = ["name"]
138138
managedby = var.managedby
139-
enabled = var.enabled
139+
enabled = var.enabled && var.only_guardduty_enable
140140

141141
filename = format("%s/slack", path.module)
142142
handler = "index.handler"

modules/guardduty/variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ variable "guardduty_enable" {
3636
description = "Enable monitoring and feedback reporting. Setting to false is equivalent to `suspending` GuardDuty. Defaults to true"
3737
}
3838

39+
variable "only_guardduty_enable" {
40+
type = bool
41+
default = true
42+
description = "Enable monitoring and feedback reporting. Setting to false is equivalent to `suspending` GuardDuty. Defaults to true"
43+
}
44+
3945
variable "ipset_iplist" {
4046
type = list(any)
4147
description = "IPSet list of trusted IP addresses"
@@ -48,6 +54,18 @@ variable "target_bucket" {
4854
description = "The name of the bucket that will receive the log objects."
4955
}
5056

57+
variable "ipset_location" {
58+
type = string
59+
default = ""
60+
description = "Location of ipset in s3."
61+
}
62+
63+
variable "threatintelset_iplist_location" {
64+
type = string
65+
default = ""
66+
description = "Location of threatintelset ipset in s3."
67+
}
68+
5169
variable "target_prefix" {
5270
type = string
5371
default = ""

variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ variable "guardduty_enable" {
226226
description = "Enable monitoring and feedback reporting. Setting to false is equivalent to `suspending` GuardDuty. Defaults to true"
227227
}
228228

229+
variable "only_guardduty_enable" {
230+
type = bool
231+
default = true
232+
description = "Enable monitoring and feedback reporting. Setting to false is equivalent to `suspending` GuardDuty. Defaults to true"
233+
}
234+
229235
variable "guardduty_s3_bucket_name" {
230236
type = string
231237
description = "The name of the S3 bucket which will store guardduty files."
@@ -1829,3 +1835,15 @@ variable "config_role_arn" {
18291835
default = ""
18301836
description = "config role arn"
18311837
}
1838+
1839+
variable "ipset_location" {
1840+
type = string
1841+
default = ""
1842+
description = "Location of ipset in s3."
1843+
}
1844+
1845+
variable "threatintelset_iplist_location" {
1846+
type = string
1847+
default = ""
1848+
description = "Location of threatintelset ipset in s3."
1849+
}

0 commit comments

Comments
 (0)