From e061b364fdb6676982c31fa989266b20c45efaf8 Mon Sep 17 00:00:00 2001 From: Shikha Maheshwari Date: Fri, 19 Apr 2024 13:46:49 +0530 Subject: [PATCH] fix: fixed [bug](https://github.com/terraform-ibm-modules/terraform-ibm-hpcs/issues/173) introduced with terraform 1.6 where the following error occurred: `Invalid for_each argument` (#183) --- .secrets.baseline | 2 +- main.tf | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index c9258ee..3ee8a92 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -3,7 +3,7 @@ "files": "go.sum|^.secrets.baseline$", "lines": null }, - "generated_at": "2023-12-11T13:43:02Z", + "generated_at": "2024-04-18T13:59:04Z", "plugins_used": [ { "name": "AWSKeyDetector" diff --git a/main.tf b/main.tf index ef44a01..d12dc22 100644 --- a/main.tf +++ b/main.tf @@ -16,7 +16,8 @@ locals { # tflint-ignore: terraform_unused_declarations validate_admins_variables = var.auto_initialization_using_recovery_crypto_units == true ? ((length(var.admins) == 0 && length(var.base64_encoded_admins) == 0) || (length(var.admins) != 0 && length(var.base64_encoded_admins) != 0) ? tobool("Please provide exactly one of admins or base64_encoded_admins. Passing neither or both is invalid.") : true) : true - admins_map = length(var.base64_encoded_admins) != 0 ? { for admin in var.base64_encoded_admins : admin.name => admin } : null + admins_name_map = merge([for admin in var.base64_encoded_admins : { (admin.name) = { "name" = admin.name } }]...) # map created for non-sensitive value (admin name) only + admins_map = length(var.base64_encoded_admins) != 0 ? { for admin in var.base64_encoded_admins : admin.name => admin } : null admins = local.admins_map != null ? [ for admin in var.base64_encoded_admins : { name = admin.name @@ -24,6 +25,10 @@ locals { token = admin.token } ] : var.admins + + # Following is the fix for the issue https://github.com/terraform-ibm-modules/terraform-ibm-hpcs/issues/173 + temp_map = (local.admins_name_map == null) ? {} : local.admins_name_map + nonsensitive_value_map = (local.temp_map == {}) ? {} : nonsensitive(local.temp_map) } resource "ibm_hpcs" "hpcs_instance" { @@ -58,8 +63,8 @@ resource "ibm_hpcs" "hpcs_instance" { } resource "local_file" "admin_files" { - for_each = local.admins_map != null ? nonsensitive(local.admins_map) : {} - content_base64 = each.value.key + for_each = (local.nonsensitive_value_map) + content_base64 = local.admins_map[each.key].key filename = "${path.module}/${each.key}.sigkey" }