Skip to content

Commit

Permalink
fix: Fixed incorrect tomap() (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbabenko authored Jan 21, 2022
1 parent 8c76cbd commit 05bceba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
7 changes: 7 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ EOF
effect = "Deny",
actions = ["s3:HeadObject", "s3:GetObject"],
resources = ["arn:aws:s3:::my-bucket/*"]
condition = {
stringequals_condition = {
test = "StringEquals"
variable = "aws:PrincipalOrgID"
values = ["123456789012"]
}
}
}
}

Expand Down
16 changes: 4 additions & 12 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ resource "aws_cloudwatch_event_bus" "this" {
}

resource "aws_cloudwatch_event_rule" "this" {
for_each = var.create && var.create_rules ? {
for rule in local.eventbridge_rules : rule.name => rule
} : {}
for_each = { for k, v in local.eventbridge_rules : v.name => v if var.create && var.create_rules }

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

resource "aws_cloudwatch_event_target" "this" {
for_each = var.create && var.create_targets ? {
for target in local.eventbridge_targets : target.name => target
} : tomap({})
for_each = { for k, v in local.eventbridge_targets : v.name => v if var.create && var.create_targets }

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

Expand Down Expand Up @@ -205,9 +201,7 @@ resource "aws_cloudwatch_event_permission" "this" {
}

resource "aws_cloudwatch_event_connection" "this" {
for_each = var.create && var.create_connections ? {
for conn in local.eventbridge_connections : conn.name => conn
} : tomap({})
for_each = { for k, v in local.eventbridge_connections : v.name => v if var.create && var.create_connections }

name = each.value.Name
description = lookup(each.value, "description", null)
Expand Down Expand Up @@ -339,9 +333,7 @@ resource "aws_cloudwatch_event_connection" "this" {
}

resource "aws_cloudwatch_event_api_destination" "this" {
for_each = var.create && var.create_api_destinations ? {
for dest in local.eventbridge_api_destinations : dest.name => dest
} : {}
for_each = { for k, v in local.eventbridge_api_destinations : v.name => v if var.create && var.create_api_destinations }

name = each.value.Name
description = lookup(each.value, "description", null)
Expand Down
10 changes: 5 additions & 5 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ output "eventbridge_bus_name" {

output "eventbridge_bus_arn" {
description = "The EventBridge Bus Arn"
value = element(concat(aws_cloudwatch_event_bus.this.*.arn, [""]), 0)
value = try(aws_cloudwatch_event_bus.this[0].arn, "")
}

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

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

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

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

0 comments on commit 05bceba

Please sign in to comment.