diff --git a/main.tf b/main.tf index 76a5860..aef754b 100644 --- a/main.tf +++ b/main.tf @@ -73,7 +73,7 @@ resource "aws_iam_role" "this" { ############################## data "aws_iam_policy_document" "service" { - for_each = local.create_role && var.attach_policies_for_integrations ? var.service_integrations : tomap({}) + for_each = local.create_role && var.attach_policies_for_integrations ? try(tomap(var.service_integrations), var.service_integrations) : tomap({}) dynamic "statement" { for_each = each.value @@ -97,14 +97,14 @@ data "aws_iam_policy_document" "service" { } resource "aws_iam_policy" "service" { - for_each = local.create_role && var.attach_policies_for_integrations ? var.service_integrations : tomap({}) + for_each = local.create_role && var.attach_policies_for_integrations ? try(tomap(var.service_integrations), var.service_integrations) : tomap({}) name = "${local.role_name}-${each.key}" policy = data.aws_iam_policy_document.service[each.key].json } resource "aws_iam_policy_attachment" "service" { - for_each = local.create_role && var.attach_policies_for_integrations ? var.service_integrations : tomap({}) + for_each = local.create_role && var.attach_policies_for_integrations ? try(tomap(var.service_integrations), var.service_integrations) : tomap({}) name = "${local.role_name}-${each.key}" roles = [aws_iam_role.this[0].name]