Skip to content

Commit 6d5ab1a

Browse files
author
sourabh
committed
updating kinesisfirehoseformetrics for IAM role conditions.
1 parent 067552a commit 6d5ab1a

File tree

7 files changed

+24
-15
lines changed

7 files changed

+24
-15
lines changed

aws/kinesisfirehoseformetrics/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ This module is used to create the SumoLogic AWS Kinesis Firehose for Metrics sou
3333
| 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 Kinesis Firehose for Metrics Collector <Random ID>",<br> "description": "This collector is created using Sumo Logic terraform AWS Kinesis Firehose for metrics module to collect AWS cloudwatch metrics.",<br> "fields": {}<br>}</pre> | no |
3434
| create\_bucket | Provide "true" if you would like to create AWS S3 bucket to store failed logs. Provide "bucket\_details" if set to "false". | `bool` | `true` | no |
3535
| create\_collector | Provide "true" if you would like to create the Sumo Logic Collector. | `bool` | n/a | yes |
36-
| source\_details | Provide details for the Sumo Logic Kinesis Firehose for 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> sumo_account_id = number<br> limit_to_namespaces = list(string)<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 Kinesis Firehose for metrics module to collect AWS Cloudwatch metrics.",<br> "fields": {},<br> "iam_role_arn": "",<br> "limit_to_namespaces": [],<br> "source_category": "Labs/aws/cloudwatch/metrics",<br> "source_name": "Kinesis Firehose for Metrics Source",<br> "sumo_account_id": 926226587429<br>}</pre> | no |
36+
| source\_details | Provide details for the Sumo Logic Kinesis Firehose for 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> sumo_account_id = number<br> limit_to_namespaces = list(string)<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 Kinesis Firehose for 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> "source_category": "Labs/aws/cloudwatch/metrics",<br> "source_name": "Kinesis Firehose for Metrics Source",<br> "sumo_account_id": 926226587429<br>}</pre> | no |
3737
| 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 |
3838

3939
## Outputs

aws/kinesisfirehoseformetrics/kinesisfirehoseformetrics.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ resource "aws_cloudwatch_metric_stream" "metric_stream" {
145145
}
146146

147147
resource "aws_iam_role" "source_iam_role" {
148-
for_each = toset(local.create_iam_role ? ["source_iam_role"] : [])
148+
for_each = toset(var.source_details.iam_details.create_iam_role ? ["source_iam_role"] : [])
149149

150150
name = "SumoLogic-Kinesis-firehose-Metrics-Module-${random_string.aws_random.id}"
151151
path = "/"
@@ -161,7 +161,7 @@ resource "aws_iam_role" "source_iam_role" {
161161
}
162162

163163
resource "aws_iam_policy" "iam_policy" {
164-
for_each = toset(local.create_iam_role ? ["iam_policy"] : [])
164+
for_each = toset(var.source_details.iam_details.create_iam_role ? ["iam_policy"] : [])
165165

166166
name = "SumoLogicCloudWatchMetricsSource-${random_string.aws_random.id}"
167167
policy = templatefile("${path.module}/templates/sumologic_source_policy.tmpl", {})
@@ -192,7 +192,7 @@ resource "sumologic_kinesis_metrics_source" "source" {
192192

193193
authentication {
194194
type = "AWSRoleBasedAuthentication"
195-
role_arn = local.create_iam_role ? aws_iam_role.source_iam_role["source_iam_role"].arn : var.source_details.iam_role_arn
195+
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
196196
}
197197

198198
path {

aws/kinesisfirehoseformetrics/locals.tf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,4 @@ locals {
4141

4242
# Get the default collector name if no collector name is provided.
4343
collector_name = var.collector_details.collector_name == "SumoLogic Kinesis Firehose for Metrics Collector <Random ID>" ? "SumoLogic Kinesis Firehose for Metrics Collector ${random_string.aws_random.id}" : var.collector_details.collector_name
44-
45-
# Create IAM role condition if no IAM ROLE ARN is provided.
46-
create_iam_role = var.source_details.iam_role_arn != "" ? false : true
4744
}

aws/kinesisfirehoseformetrics/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ output "aws_cloudwatch_log_stream" {
1919
}
2020

2121
output "source_aws_iam_role" {
22-
value = local.create_iam_role ? aws_iam_role.source_iam_role : {}
22+
value = var.source_details.iam_details.create_iam_role ? aws_iam_role.source_iam_role : {}
2323
description = "AWS IAM role with permission to setup Sumo Logic permissions."
2424
}
2525

aws/kinesisfirehoseformetrics/variables.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ variable "source_details" {
4444
sumo_account_id = number
4545
limit_to_namespaces = list(string)
4646
fields = map(string)
47-
iam_role_arn = string
47+
iam_details = object({
48+
create_iam_role = bool
49+
iam_role_arn = string
50+
})
4851
})
4952
description = "Provide details for the Sumo Logic Kinesis Firehose for Metrics source. If not provided, then defaults will be used."
5053
default = {
@@ -55,7 +58,10 @@ variable "source_details" {
5558
sumo_account_id = 926226587429
5659
limit_to_namespaces = []
5760
fields = {}
58-
iam_role_arn = ""
61+
iam_details = {
62+
create_iam_role = true
63+
iam_role_arn = null
64+
}
5965
}
6066
}
6167

terratest/aws/cloudwatchmetrics/cloudwatchmetrics_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func TestUpdates(t *testing.T) {
174174
"sumo_account_id": "926226587429",
175175
"collector_id": "",
176176
"iam_details": map[string]interface{}{
177-
"create_iam_role": false,
177+
"create_iam_role": true,
178178
"iam_role_arn": nil,
179179
},
180180
},
@@ -212,7 +212,7 @@ func TestUpdates(t *testing.T) {
212212
"sumo_account_id": "926226587429",
213213
"collector_id": "",
214214
"iam_details": map[string]interface{}{
215-
"create_iam_role": false,
215+
"create_iam_role": true,
216216
"iam_role_arn": nil,
217217
},
218218
},
@@ -243,7 +243,7 @@ func TestUpdates(t *testing.T) {
243243
"sumo_account_id": "926226587429",
244244
"collector_id": COLLECTOR_ID,
245245
"iam_details": map[string]interface{}{
246-
"create_iam_role": false,
246+
"create_iam_role": true,
247247
"iam_role_arn": nil,
248248
},
249249
},

terratest/aws/kinesisfirehoseformetrics/kinesisfirehoseformetrics_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ func TestWithExistingValues(t *testing.T) {
9595
},
9696
"sumo_account_id": "926226587429",
9797
"limit_to_namespaces": []string{"AWS/SNS", "AWS/SQS", "AWS/Events", "AWS/Lambda", "AWS/Logs", "AWS/S3", "AWS/Firehose"},
98-
"iam_role_arn": IAM_ROLE,
98+
"iam_details": map[string]interface{}{
99+
"create_iam_role": false,
100+
"iam_role_arn": IAM_ROLE,
101+
},
99102
},
100103
"sumologic_organization_id": common.SumologicOrganizationId,
101104
}
@@ -194,7 +197,10 @@ func TestUpdates(t *testing.T) {
194197
},
195198
"sumo_account_id": "926226587429",
196199
"limit_to_namespaces": []string{"AWS/SNS", "AWS/SQS", "AWS/Events"},
197-
"iam_role_arn": "",
200+
"iam_details": map[string]interface{}{
201+
"create_iam_role": true,
202+
"iam_role_arn": nil,
203+
},
198204
},
199205
"sumologic_organization_id": common.SumologicOrganizationId,
200206
}

0 commit comments

Comments
 (0)