From 05bceba343470ab41272a2345ec45da86d1721f0 Mon Sep 17 00:00:00 2001 From: Anton Babenko Date: Fri, 21 Jan 2022 16:58:18 +0100 Subject: [PATCH] fix: Fixed incorrect tomap() (#39) --- examples/complete/main.tf | 7 +++++++ main.tf | 16 ++++------------ outputs.tf | 10 +++++----- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/examples/complete/main.tf b/examples/complete/main.tf index d0c98b9..ee6489d 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -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"] + } + } } } diff --git a/main.tf b/main.tf index 3537ce3..f5fbe7f 100644 --- a/main.tf +++ b/main.tf @@ -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) @@ -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 @@ -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) @@ -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) diff --git a/outputs.tf b/outputs.tf index 360c7de..ef9abea 100644 --- a/outputs.tf +++ b/outputs.tf @@ -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 @@ -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, "") }