Skip to content

Commit 067552a

Browse files
author
sourabh
committed
updating CloudWatchMetrics module to add condition for IAM role create.
1 parent 3a2c89e commit 067552a

File tree

6 files changed

+33
-14
lines changed

6 files changed

+33
-14
lines changed

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

terratest/aws/cloudwatchmetrics/cloudwatchmetrics_test.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ func TestWithDefaultValues(t *testing.T) {
5555
},
5656
"sumo_account_id": "926226587429",
5757
"collector_id": "",
58-
"iam_role_arn": "",
58+
"iam_details": map[string]interface{}{
59+
"create_iam_role": true,
60+
"iam_role_arn": nil,
61+
},
5962
},
6063
}
6164

@@ -115,7 +118,10 @@ func TestWithExistingValues(t *testing.T) {
115118
},
116119
"sumo_account_id": "926226587429",
117120
"collector_id": COLLECTOR_ID,
118-
"iam_role_arn": IAM_ROLE,
121+
"iam_details": map[string]interface{}{
122+
"create_iam_role": false,
123+
"iam_role_arn": IAM_ROLE,
124+
},
119125
},
120126
}
121127

@@ -167,7 +173,10 @@ func TestUpdates(t *testing.T) {
167173
},
168174
"sumo_account_id": "926226587429",
169175
"collector_id": "",
170-
"iam_role_arn": "",
176+
"iam_details": map[string]interface{}{
177+
"create_iam_role": false,
178+
"iam_role_arn": nil,
179+
},
171180
},
172181
}
173182

@@ -202,7 +211,10 @@ func TestUpdates(t *testing.T) {
202211
},
203212
"sumo_account_id": "926226587429",
204213
"collector_id": "",
205-
"iam_role_arn": "",
214+
"iam_details": map[string]interface{}{
215+
"create_iam_role": false,
216+
"iam_role_arn": nil,
217+
},
206218
},
207219
}
208220

@@ -230,7 +242,10 @@ func TestUpdates(t *testing.T) {
230242
},
231243
"sumo_account_id": "926226587429",
232244
"collector_id": COLLECTOR_ID,
233-
"iam_role_arn": "",
245+
"iam_details": map[string]interface{}{
246+
"create_iam_role": false,
247+
"iam_role_arn": nil,
248+
},
234249
},
235250
}
236251

0 commit comments

Comments
 (0)