Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b8db797

Browse files
jor2Jordan-Williams2
andauthored
fix: add better error handling when incorrect profile name is passed to the attachments submodule (#204)
Co-authored-by: Jordan-Williams2 <[email protected]>
1 parent d460955 commit b8db797

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

modules/attachment/main.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ locals {
3535
]
3636
)
3737

38+
validate_profile_name = length(local.sorted_list) == 0 ? tobool("Could not find a valid profile name ${var.profile_name}") : true
39+
3840
# Retrieve profile with the latest version by getting last element in sorted list
39-
latest_profile = local.sorted_list[length(local.sorted_list) - 1]
41+
latest_profile = local.validate_profile_name ? local.sorted_list[length(local.sorted_list) - 1] : null
4042

4143
profile_map = var.profile_version == "latest" ? {
4244
(var.profile_name) = local.latest_profile
@@ -46,9 +48,9 @@ locals {
4648
}
4749

4850
# tflint-ignore: terraform_unused_declarations
49-
validate_profile = lookup(local.profile_map, var.profile_name, null) == null ? tobool("Could not find a valid profile name ${var.profile_name} and matching version ${var.profile_version}") : true
51+
validate_profile_version = lookup(local.profile_map, var.profile_name, null) == null ? tobool("Could not find a valid profile name ${var.profile_name} and matching version ${var.profile_version}") : true
5052

51-
profile = local.validate_profile ? local.profile_map[var.profile_name] : null
53+
profile = local.validate_profile_version ? local.profile_map[var.profile_name] : null
5254
}
5355

5456
data "ibm_scc_profile" "scc_profile" {

0 commit comments

Comments
 (0)