Skip to content

Commit

Permalink
fix: fixed [bug](#173) introduced with terraform 1.6 where the follow…
Browse files Browse the repository at this point in the history
…ing error occurred: `Invalid for_each argument` (#183)
  • Loading branch information
maheshwarishikha authored Apr 19, 2024
1 parent 55b9924 commit e061b36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 8 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ 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
key = local_file.admin_files[admin.name].filename
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" {
Expand Down Expand Up @@ -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"
}

Expand Down

0 comments on commit e061b36

Please sign in to comment.