Skip to content

Commit 1111ffe

Browse files
authored
Merge pull request #7 from SumoLogic/aws
Updating modules for conditions related to role and sns topic
2 parents a96459e + 58f9068 commit 1111ffe

38 files changed

+220
-110
lines changed

aws/cloudtrail/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ This module is used to create AWS and Sumo Logic resource to collect CloudTrail
3535
| collector\_details | Provide details for the Sumo Logic collector. If not provided, then defaults will be used. | <pre>object({<br> collector_name = string<br> description = string<br> fields = map(string)<br> })</pre> | <pre>{<br> "collector_name": "SumoLogic CloudTrail Collector <Random ID>",<br> "description": "This collector is created using Sumo Logic terraform AWS cloudtrail module to collect AWS cloudtrail logs.",<br> "fields": {}<br>}</pre> | no |
3636
| create\_collector | Provide "true" if you would like to create the Sumo Logic Collector. | `bool` | n/a | yes |
3737
| create\_trail | Provide "true" if you would like to create the AWS CloudTrail. If the bucket is created by the module, module by default creates the AWS cloudtrail. | `bool` | n/a | yes |
38-
| source\_details | Provide details for the Sumo Logic CloudTrail source. If not provided, then defaults will be used. | <pre>object({<br> source_name = string<br> source_category = string<br> collector_id = string<br> description = string<br> bucket_details = object({<br> create_bucket = bool<br> bucket_name = string<br> path_expression = string<br> force_destroy_bucket = bool<br> })<br> paused = bool<br> scan_interval = string<br> sumo_account_id = number<br> cutoff_relative_time = string<br> fields = map(string)<br> iam_role_arn = string<br> sns_topic_arn = string<br> })</pre> | <pre>{<br> "bucket_details": {<br> "bucket_name": "cloudtrail-logs-random-id",<br> "create_bucket": true,<br> "force_destroy_bucket": true,<br> "path_expression": "AWSLogs/<ACCOUNT-ID>/CloudTrail/<REGION-NAME>/*"<br> },<br> "collector_id": "",<br> "cutoff_relative_time": "-1d",<br> "description": "This source is created using Sumo Logic terraform AWS cloudtrail module to collect AWS cloudtrail logs.",<br> "fields": {},<br> "iam_role_arn": "",<br> "paused": false,<br> "scan_interval": 300000,<br> "sns_topic_arn": "",<br> "source_category": "Labs/aws/cloudtrail",<br> "source_name": "CloudTrail Source",<br> "sumo_account_id": 926226587429<br>}</pre> | no |
38+
| source\_details | Provide details for the Sumo Logic CloudTrail source. If not provided, then defaults will be used. | <pre>object({<br> source_name = string<br> source_category = string<br> collector_id = string<br> description = string<br> bucket_details = object({<br> create_bucket = bool<br> bucket_name = string<br> path_expression = string<br> force_destroy_bucket = bool<br> })<br> paused = bool<br> scan_interval = string<br> sumo_account_id = number<br> cutoff_relative_time = string<br> fields = map(string)<br> iam_details = object({<br> create_iam_role = bool<br> iam_role_arn = string<br> })<br> sns_topic_details = object({<br> create_sns_topic = bool<br> sns_topic_arn = string<br> })<br> })</pre> | <pre>{<br> "bucket_details": {<br> "bucket_name": "cloudtrail-logs-random-id",<br> "create_bucket": true,<br> "force_destroy_bucket": true,<br> "path_expression": "AWSLogs/<ACCOUNT-ID>/CloudTrail/<REGION-NAME>/*"<br> },<br> "collector_id": "",<br> "cutoff_relative_time": "-1d",<br> "description": "This source is created using Sumo Logic terraform AWS cloudtrail module to collect AWS cloudtrail logs.",<br> "fields": {},<br> "iam_details": {<br> "create_iam_role": true,<br> "iam_role_arn": null<br> },<br> "paused": false,<br> "scan_interval": 300000,<br> "sns_topic_details": {<br> "create_sns_topic": true,<br> "sns_topic_arn": null<br> },<br> "source_category": "Labs/aws/cloudtrail",<br> "source_name": "CloudTrail Source",<br> "sumo_account_id": 926226587429<br>}</pre> | no |
3939
| sumologic\_organization\_id | Appears on the Account Overview page that displays information about your Sumo Logic organization. Used for IAM Role in Sumo Logic AWS Sources. | `string` | n/a | yes |
4040

4141
## Outputs

aws/cloudtrail/cloudtrail.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ resource "aws_s3_bucket" "s3_bucket" {
2424
}
2525

2626
resource "aws_sns_topic" "sns_topic" {
27-
for_each = toset(local.create_sns_topic ? ["sns_topic"] : [])
27+
for_each = toset(var.source_details.sns_topic_details.create_sns_topic ? ["sns_topic"] : [])
2828

2929
name = "SumoLogic-Terraform-CloudTrail-Module-${random_string.aws_random.id}"
3030
policy = templatefile("${path.module}/templates/sns_topic_policy.tmpl", {
@@ -36,7 +36,7 @@ resource "aws_sns_topic" "sns_topic" {
3636
}
3737

3838
resource "aws_s3_bucket_notification" "bucket_notification" {
39-
for_each = toset(local.create_sns_topic && var.source_details.bucket_details.create_bucket ? ["bucket_notification"] : [])
39+
for_each = toset(var.source_details.sns_topic_details.create_sns_topic && var.source_details.bucket_details.create_bucket ? ["bucket_notification"] : [])
4040

4141
bucket = aws_s3_bucket.s3_bucket["s3_bucket"].id
4242

@@ -57,7 +57,7 @@ resource "aws_cloudtrail" "cloudtrail" {
5757
}
5858

5959
resource "aws_iam_role" "source_iam_role" {
60-
for_each = toset(local.create_iam_role ? ["source_iam_role"] : [])
60+
for_each = toset(var.source_details.iam_details.create_iam_role ? ["source_iam_role"] : [])
6161

6262
name = "SumoLogic-Terraform-CloudTrail-Module-${random_string.aws_random.id}"
6363
path = "/"
@@ -72,7 +72,7 @@ resource "aws_iam_role" "source_iam_role" {
7272
}
7373

7474
resource "aws_iam_policy" "iam_policy" {
75-
for_each = toset(local.create_iam_role ? ["iam_policy"] : [])
75+
for_each = toset(var.source_details.iam_details.create_iam_role ? ["iam_policy"] : [])
7676

7777
name = "SumoLogicCloudTrailSource-${random_string.aws_random.id}"
7878
policy = templatefile("${path.module}/templates/sumologic_source_policy.tmpl", {
@@ -111,7 +111,7 @@ resource "sumologic_cloudtrail_source" "source" {
111111
scan_interval = var.source_details.scan_interval
112112
authentication {
113113
type = "AWSRoleBasedAuthentication"
114-
role_arn = local.create_iam_role ? aws_iam_role.source_iam_role["source_iam_role"].arn : var.source_details.iam_role_arn
114+
role_arn = var.source_details.iam_details.create_iam_role ? aws_iam_role.source_iam_role["source_iam_role"].arn : var.source_details.iam_details.iam_role_arn
115115
}
116116

117117
path {
@@ -139,5 +139,5 @@ resource "aws_sns_topic_subscription" "subscription" {
139139
endpoint = sumologic_cloudtrail_source.source.url
140140
endpoint_auto_confirms = true
141141
protocol = "https"
142-
topic_arn = local.create_sns_topic ? aws_sns_topic.sns_topic["sns_topic"].arn : var.source_details.sns_topic_arn
142+
topic_arn = var.source_details.sns_topic_details.create_sns_topic ? aws_sns_topic.sns_topic["sns_topic"].arn : var.source_details.sns_topic_details.sns_topic_arn
143143
}

aws/cloudtrail/locals.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ locals {
1313
# Get the default bucket name when no bucket is provided and create_bucket is true.
1414
bucket_name = var.source_details.bucket_details.create_bucket && var.source_details.bucket_details.bucket_name == "cloudtrail-logs-random-id" ? "cloudtrail-logs-${random_string.aws_random.id}" : var.source_details.bucket_details.bucket_name
1515

16-
# Create IAM role condition if no IAM ROLE ARN is provided.
17-
create_iam_role = var.source_details.iam_role_arn != "" ? false : true
18-
19-
# Create SNS topic condition if no SNS topic arn is provided.
20-
create_sns_topic = var.source_details.sns_topic_arn != "" ? false : true
21-
2216
# Trail should be created when we create the bucket. If we do not create the bucket, user should have capability to create and not create trail.
2317
create_trail = var.source_details.bucket_details.create_bucket ? true : var.create_trail
2418

aws/cloudtrail/outputs.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ output "aws_s3_bucket" {
99
}
1010

1111
output "aws_sns_topic" {
12-
value = local.create_sns_topic ? aws_sns_topic.sns_topic : {}
12+
value = var.source_details.sns_topic_details.create_sns_topic ? aws_sns_topic.sns_topic : {}
1313
description = "AWS SNS topic attached to the AWS S3 bucket."
1414
}
1515

1616
output "aws_s3_bucket_notification" {
17-
value = local.create_sns_topic && var.source_details.bucket_details.create_bucket ? aws_s3_bucket_notification.bucket_notification : {}
17+
value = var.source_details.sns_topic_details.create_sns_topic && var.source_details.bucket_details.create_bucket ? aws_s3_bucket_notification.bucket_notification : {}
1818
description = "AWS S3 Bucket Notification attached to the AWS S3 Bucket"
1919
}
2020

@@ -24,7 +24,7 @@ output "aws_cloudtrail" {
2424
}
2525

2626
output "aws_iam_role" {
27-
value = local.create_iam_role ? aws_iam_role.source_iam_role : {}
27+
value = var.source_details.iam_details.create_iam_role ? aws_iam_role.source_iam_role : {}
2828
description = "AWS IAM role with permission to allow Sumo Logic to read logs from S3 Bucket."
2929
}
3030

aws/cloudtrail/variables.tf

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,14 @@ variable "source_details" {
3434
sumo_account_id = number
3535
cutoff_relative_time = string
3636
fields = map(string)
37-
iam_role_arn = string
38-
sns_topic_arn = string
37+
iam_details = object({
38+
create_iam_role = bool
39+
iam_role_arn = string
40+
})
41+
sns_topic_details = object({
42+
create_sns_topic = bool
43+
sns_topic_arn = string
44+
})
3945
})
4046
description = "Provide details for the Sumo Logic CloudTrail source. If not provided, then defaults will be used."
4147
default = {
@@ -54,8 +60,14 @@ variable "source_details" {
5460
sumo_account_id = 926226587429
5561
cutoff_relative_time = "-1d"
5662
fields = {}
57-
iam_role_arn = ""
58-
sns_topic_arn = ""
63+
iam_details = {
64+
create_iam_role = true
65+
iam_role_arn = null
66+
}
67+
sns_topic_details = {
68+
create_sns_topic = true
69+
sns_topic_arn = null
70+
}
5971
}
6072
validation {
6173
condition = can(regex("[a-z0-9-.]{3,63}$", var.source_details.bucket_details.bucket_name))

aws/cloudwatchmetrics/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ This module is used to create the SumoLogic AWS CloudWatch metrics source. Featu
3030
|------|-------------|------|---------|:--------:|
3131
| collector\_details | Provide details for the Sumo Logic collector. If not provided, then defaults will be used. | <pre>object({<br> collector_name = string<br> description = string<br> fields = map(string)<br> })</pre> | <pre>{<br> "collector_name": "SumoLogic CloudWatch Metrics Collector <Random ID>",<br> "description": "This collector is created using Sumo Logic terraform AWS Cloudwatch metrics module to collect AWS cloudwatch metrics.",<br> "fields": {}<br>}</pre> | no |
3232
| create\_collector | Provide "true" if you would like to create the Sumo Logic Collector. | `bool` | n/a | yes |
33-
| source\_details | Provide details for the Sumo Logic Cloudwatch Metrics source. If not provided, then defaults will be used. | <pre>object({<br> source_name = string<br> source_category = string<br> collector_id = string<br> description = string<br> limit_to_regions = list(string)<br> limit_to_namespaces = list(string)<br> paused = bool<br> scan_interval = number<br> sumo_account_id = number<br> fields = map(string)<br> iam_role_arn = string<br> })</pre> | <pre>{<br> "collector_id": "",<br> "description": "This source is created using Sumo Logic terraform AWS CloudWatch Metrics module to collect AWS Cloudwatch metrics.",<br> "fields": {},<br> "iam_role_arn": "",<br> "limit_to_namespaces": [],<br> "limit_to_regions": [],<br> "paused": false,<br> "scan_interval": 300000,<br> "source_category": "Labs/aws/cloudwatch/metrics",<br> "source_name": "CloudWatch Metrics Source",<br> "sumo_account_id": 926226587429<br>}</pre> | no |
33+
| source\_details | Provide details for the Sumo Logic Cloudwatch Metrics source. If not provided, then defaults will be used. | <pre>object({<br> source_name = string<br> source_category = string<br> collector_id = string<br> description = string<br> limit_to_regions = list(string)<br> limit_to_namespaces = list(string)<br> paused = bool<br> scan_interval = number<br> sumo_account_id = number<br> fields = map(string)<br> iam_details = object({<br> create_iam_role = bool<br> iam_role_arn = string<br> })<br> })</pre> | <pre>{<br> "collector_id": "",<br> "description": "This source is created using Sumo Logic terraform AWS CloudWatch Metrics module to collect AWS Cloudwatch metrics.",<br> "fields": {},<br> "iam_details": {<br> "create_iam_role": true,<br> "iam_role_arn": null<br> },<br> "limit_to_namespaces": [],<br> "limit_to_regions": [],<br> "paused": false,<br> "scan_interval": 300000,<br> "source_category": "Labs/aws/cloudwatch/metrics",<br> "source_name": "CloudWatch Metrics Source",<br> "sumo_account_id": 926226587429<br>}</pre> | no |
3434
| sumologic\_organization\_id | Appears on the Account Overview page that displays information about your Sumo Logic organization. Used for IAM Role in Sumo Logic AWS Sources. | `string` | n/a | yes |
3535

3636
## Outputs

aws/cloudwatchmetrics/cloudwatchmetrics.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ resource "random_string" "aws_random" {
99
}
1010

1111
resource "aws_iam_role" "source_iam_role" {
12-
for_each = toset(local.create_iam_role ? ["source_iam_role"] : [])
12+
for_each = toset(var.source_details.iam_details.create_iam_role ? ["source_iam_role"] : [])
1313

1414
name = "SumoLogic-CloudWatch-Metrics-Module-${random_string.aws_random.id}"
1515
path = "/"
@@ -24,7 +24,7 @@ resource "aws_iam_role" "source_iam_role" {
2424
}
2525

2626
resource "aws_iam_policy" "iam_policy" {
27-
for_each = toset(local.create_iam_role ? ["iam_policy"] : [])
27+
for_each = toset(var.source_details.iam_details.create_iam_role ? ["iam_policy"] : [])
2828

2929
name = "SumoLogicCloudWatchMetricsSource-${random_string.aws_random.id}"
3030
policy = templatefile("${path.module}/templates/sumologic_source_policy.tmpl", {})
@@ -57,7 +57,7 @@ resource "sumologic_cloudwatch_source" "cloudwatch_metrics_sources" {
5757

5858
authentication {
5959
type = "AWSRoleBasedAuthentication"
60-
role_arn = local.create_iam_role ? aws_iam_role.source_iam_role["source_iam_role"].arn : var.source_details.iam_role_arn
60+
role_arn = var.source_details.iam_details.create_iam_role ? aws_iam_role.source_iam_role["source_iam_role"].arn : var.source_details.iam_details.iam_role_arn
6161
}
6262

6363
path {

aws/cloudwatchmetrics/locals.tf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@ locals {
33
# Get the default collector name if no collector name is provided.
44
collector_name = var.collector_details.collector_name == "SumoLogic CloudWatch Metrics Collector <Random ID>" ? "SumoLogic CloudWatch Metrics Collector ${random_string.aws_random.id}" : var.collector_details.collector_name
55

6-
# Create IAM role condition if no IAM ROLE ARN is provided.
7-
create_iam_role = var.source_details.iam_role_arn != "" ? false : true
86
}

aws/cloudwatchmetrics/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ output "random_string" {
44
}
55

66
output "aws_iam_role" {
7-
value = local.create_iam_role ? aws_iam_role.source_iam_role : {}
7+
value = var.source_details.iam_details.create_iam_role ? aws_iam_role.source_iam_role : {}
88
description = "AWS IAM role with permission to allow Sumo Logic to read logs from S3 Bucket."
99
}
1010

aws/cloudwatchmetrics/variables.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ variable "source_details" {
2929
scan_interval = number
3030
sumo_account_id = number
3131
fields = map(string)
32-
iam_role_arn = string
32+
iam_details = object({
33+
create_iam_role = bool
34+
iam_role_arn = string
35+
})
3336
})
3437
description = "Provide details for the Sumo Logic Cloudwatch Metrics source. If not provided, then defaults will be used."
3538
default = {
@@ -43,7 +46,10 @@ variable "source_details" {
4346
paused = false
4447
sumo_account_id = 926226587429
4548
fields = {}
46-
iam_role_arn = ""
49+
iam_details = {
50+
create_iam_role = true
51+
iam_role_arn = null
52+
}
4753
}
4854
}
4955

0 commit comments

Comments
 (0)