Skip to content

Commit e061b36

Browse files
fix: fixed [bug](#173) introduced with terraform 1.6 where the following error occurred: Invalid for_each argument (#183)
1 parent 55b9924 commit e061b36

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

.secrets.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "go.sum|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2023-12-11T13:43:02Z",
6+
"generated_at": "2024-04-18T13:59:04Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"

main.tf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@ locals {
1616
# tflint-ignore: terraform_unused_declarations
1717
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
1818

19-
admins_map = length(var.base64_encoded_admins) != 0 ? { for admin in var.base64_encoded_admins : admin.name => admin } : null
19+
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
20+
admins_map = length(var.base64_encoded_admins) != 0 ? { for admin in var.base64_encoded_admins : admin.name => admin } : null
2021
admins = local.admins_map != null ? [
2122
for admin in var.base64_encoded_admins : {
2223
name = admin.name
2324
key = local_file.admin_files[admin.name].filename
2425
token = admin.token
2526
}
2627
] : var.admins
28+
29+
# Following is the fix for the issue https://github.com/terraform-ibm-modules/terraform-ibm-hpcs/issues/173
30+
temp_map = (local.admins_name_map == null) ? {} : local.admins_name_map
31+
nonsensitive_value_map = (local.temp_map == {}) ? {} : nonsensitive(local.temp_map)
2732
}
2833

2934
resource "ibm_hpcs" "hpcs_instance" {
@@ -58,8 +63,8 @@ resource "ibm_hpcs" "hpcs_instance" {
5863
}
5964

6065
resource "local_file" "admin_files" {
61-
for_each = local.admins_map != null ? nonsensitive(local.admins_map) : {}
62-
content_base64 = each.value.key
66+
for_each = (local.nonsensitive_value_map)
67+
content_base64 = local.admins_map[each.key].key
6368
filename = "${path.module}/${each.key}.sigkey"
6469
}
6570

0 commit comments

Comments
 (0)