Skip to content

Commit 63434c8

Browse files
author
sourabh
committed
updating rootcause for iam role condition
1 parent 6d5ab1a commit 63434c8

File tree

6 files changed

+19
-13
lines changed

6 files changed

+19
-13
lines changed

aws/rootcause/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ This module is used to create the SumoLogic AWS RootCause sources. Features incl
2828

2929
| Name | Description | Type | Default | Required |
3030
|------|-------------|------|---------|:--------:|
31-
| aws\_iam\_role\_arn | Provide an existing AWS IAM role ARN value to attach to Sumo Logic sources. If this is kept empty, a new IAM role will be created. | `string` | `""` | no |
3231
| 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 RootCause Collector <Random ID>",<br> "description": "This collector is created using Sumo Logic terraform AWS Root Cause module.",<br> "fields": {}<br>}</pre> | no |
3332
| create\_collector | Provide "true" if you would like to create the Sumo Logic Collector. | `bool` | n/a | yes |
3433
| create\_inventory\_source | Provide "true" if you would like to create the Sumo Logic AWS Inventory source. | `bool` | n/a | yes |
3534
| create\_xray\_source | Provide "true" if you would like to create the Sumo Logic AWS Xray source. | `bool` | n/a | yes |
35+
| iam\_details | Provide an existing AWS IAM role ARN value to attach to Sumo Logic sources. If this is kept empty, a new IAM role will be created. | <pre>object({<br> create_iam_role = bool<br> iam_role_arn = string<br> })</pre> | <pre>{<br> "create_iam_role": true,<br> "iam_role_arn": null<br>}</pre> | no |
3636
| inventory\_source\_details | Provide details for the Sumo Logic AWS Inventory 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> })</pre> | <pre>{<br> "collector_id": "",<br> "description": "This source is created using Sumo Logic terraform AWS RootCause module to collect AWS inventory metadata.",<br> "fields": {},<br> "limit_to_namespaces": [],<br> "limit_to_regions": [],<br> "paused": false,<br> "scan_interval": 300000,<br> "source_category": "Labs/inventory",<br> "source_name": "Inventory 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
| xray\_source\_details | Provide details for the Sumo Logic AWS XRAY 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> paused = bool<br> scan_interval = number<br> sumo_account_id = number<br> fields = map(string)<br> })</pre> | <pre>{<br> "collector_id": "",<br> "description": "This source is created using Sumo Logic terraform AWS RootCause module to collect AWS Xray metrics.",<br> "fields": {},<br> "limit_to_regions": [],<br> "paused": false,<br> "scan_interval": 300000,<br> "source_category": "Labs/xray",<br> "source_name": "Xray Source",<br> "sumo_account_id": 926226587429<br>}</pre> | no |

aws/rootcause/locals.tf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ locals {
77
# Get the default collector name if no collector name is provided.
88
collector_name = var.collector_details.collector_name == "SumoLogic RootCause Collector <Random ID>" ? "SumoLogic RootCause Collector ${random_string.aws_random.id}" : var.collector_details.collector_name
99

10-
# Create IAM role condition if no IAM ROLE ARN is provided.
11-
create_iam_role = var.aws_iam_role_arn != "" ? false : true
12-
1310
# Create inventory source
1411
create_inventory_source = var.create_inventory_source
1512

aws/rootcause/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.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/rootcause/rootcause.tf

Lines changed: 4 additions & 4 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.iam_details.create_iam_role ? ["source_iam_role"] : [])
1313

1414
name = "SumoLogic-RootCause-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.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", {})
@@ -58,7 +58,7 @@ resource "sumologic_aws_inventory_source" "aws_inventory_source" {
5858

5959
authentication {
6060
type = "AWSRoleBasedAuthentication"
61-
role_arn = local.create_iam_role ? aws_iam_role.source_iam_role["source_iam_role"].arn : var.aws_iam_role_arn
61+
role_arn = var.iam_details.create_iam_role ? aws_iam_role.source_iam_role["source_iam_role"].arn : var.iam_details.iam_role_arn
6262
}
6363

6464
path {
@@ -84,7 +84,7 @@ resource "sumologic_aws_xray_source" "aws_xray_source" {
8484

8585
authentication {
8686
type = "AWSRoleBasedAuthentication"
87-
role_arn = local.create_iam_role ? aws_iam_role.source_iam_role["source_iam_role"].arn : var.aws_iam_role_arn
87+
role_arn = var.iam_details.create_iam_role ? aws_iam_role.source_iam_role["source_iam_role"].arn : var.iam_details.iam_role_arn
8888
}
8989

9090
path {

aws/rootcause/variables.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,14 @@ variable "sumologic_organization_id" {
9191
}
9292
}
9393

94-
variable "aws_iam_role_arn" {
95-
type = string
94+
variable "iam_details" {
95+
type = object({
96+
create_iam_role = bool
97+
iam_role_arn = string
98+
})
9699
description = "Provide an existing AWS IAM role ARN value to attach to Sumo Logic sources. If this is kept empty, a new IAM role will be created."
97-
default = ""
100+
default = {
101+
create_iam_role = true
102+
iam_role_arn = null
103+
}
98104
}

terratest/aws/rootcause/rootcause_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,10 @@ func TestWithExistingValues(t *testing.T) {
185185
"paused": false,
186186
"scan_interval": 60000,
187187
},
188-
"aws_iam_role_arn": IAM_ROLE,
188+
"iam_details": map[string]interface{}{
189+
"create_iam_role": false,
190+
"iam_role_arn": IAM_ROLE,
191+
},
189192
}
190193

191194
options, count := SetUpTest(t, vars, aws_region)

0 commit comments

Comments
 (0)