Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adds nonsensitive in for_each for sensitive value #183

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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