Skip to content

Commit 05bceba

Browse files
authored
fix: Fixed incorrect tomap() (#39)
1 parent 8c76cbd commit 05bceba

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

examples/complete/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ EOF
177177
effect = "Deny",
178178
actions = ["s3:HeadObject", "s3:GetObject"],
179179
resources = ["arn:aws:s3:::my-bucket/*"]
180+
condition = {
181+
stringequals_condition = {
182+
test = "StringEquals"
183+
variable = "aws:PrincipalOrgID"
184+
values = ["123456789012"]
185+
}
186+
}
180187
}
181188
}
182189

main.tf

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ resource "aws_cloudwatch_event_bus" "this" {
3939
}
4040

4141
resource "aws_cloudwatch_event_rule" "this" {
42-
for_each = var.create && var.create_rules ? {
43-
for rule in local.eventbridge_rules : rule.name => rule
44-
} : {}
42+
for_each = { for k, v in local.eventbridge_rules : v.name => v if var.create && var.create_rules }
4543

4644
name = each.value.Name
4745
name_prefix = lookup(each.value, "name_prefix", null)
@@ -60,9 +58,7 @@ resource "aws_cloudwatch_event_rule" "this" {
6058
}
6159

6260
resource "aws_cloudwatch_event_target" "this" {
63-
for_each = var.create && var.create_targets ? {
64-
for target in local.eventbridge_targets : target.name => target
65-
} : tomap({})
61+
for_each = { for k, v in local.eventbridge_targets : v.name => v if var.create && var.create_targets }
6662

6763
event_bus_name = var.create_bus ? aws_cloudwatch_event_bus.this[0].name : var.bus_name
6864

@@ -205,9 +201,7 @@ resource "aws_cloudwatch_event_permission" "this" {
205201
}
206202

207203
resource "aws_cloudwatch_event_connection" "this" {
208-
for_each = var.create && var.create_connections ? {
209-
for conn in local.eventbridge_connections : conn.name => conn
210-
} : tomap({})
204+
for_each = { for k, v in local.eventbridge_connections : v.name => v if var.create && var.create_connections }
211205

212206
name = each.value.Name
213207
description = lookup(each.value, "description", null)
@@ -339,9 +333,7 @@ resource "aws_cloudwatch_event_connection" "this" {
339333
}
340334

341335
resource "aws_cloudwatch_event_api_destination" "this" {
342-
for_each = var.create && var.create_api_destinations ? {
343-
for dest in local.eventbridge_api_destinations : dest.name => dest
344-
} : {}
336+
for_each = { for k, v in local.eventbridge_api_destinations : v.name => v if var.create && var.create_api_destinations }
345337

346338
name = each.value.Name
347339
description = lookup(each.value, "description", null)

outputs.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ output "eventbridge_bus_name" {
66

77
output "eventbridge_bus_arn" {
88
description = "The EventBridge Bus Arn"
9-
value = element(concat(aws_cloudwatch_event_bus.this.*.arn, [""]), 0)
9+
value = try(aws_cloudwatch_event_bus.this[0].arn, "")
1010
}
1111

1212
# EventBridge Archive
@@ -41,21 +41,21 @@ output "eventbridge_api_destination_arns" {
4141
# EventBridge Rule
4242
output "eventbridge_rule_ids" {
4343
description = "The EventBridge Rule IDs created"
44-
value = var.create && var.create_rules ? { for p in sort(keys(var.rules)) : p => aws_cloudwatch_event_rule.this[p].id } : {}
44+
value = { for k in sort(keys(var.rules)) : k => aws_cloudwatch_event_rule.this[k].id if var.create && var.create_rules }
4545
}
4646

4747
output "eventbridge_rule_arns" {
4848
description = "The EventBridge Rule ARNs created"
49-
value = var.create && var.create_rules ? { for p in sort(keys(var.rules)) : p => aws_cloudwatch_event_rule.this[p].arn } : {}
49+
value = { for k in sort(keys(var.rules)) : k => aws_cloudwatch_event_rule.this[k].arn if var.create && var.create_rules }
5050
}
5151

5252
# IAM Role
5353
output "eventbridge_role_arn" {
5454
description = "The ARN of the IAM role created for EventBridge"
55-
value = element(concat(aws_iam_role.eventbridge.*.arn, [""]), 0)
55+
value = try(aws_iam_role.eventbridge[0].arn, "")
5656
}
5757

5858
output "eventbridge_role_name" {
5959
description = "The name of the IAM role created for EventBridge"
60-
value = element(concat(aws_iam_role.eventbridge.*.name, [""]), 0)
60+
value = try(aws_iam_role.eventbridge[0].name, "")
6161
}

0 commit comments

Comments
 (0)