From a8f91118e969d41ad6c34724034cd6a5619c67f7 Mon Sep 17 00:00:00 2001 From: Jordan-Williams2 Date: Fri, 29 Nov 2024 11:32:45 +0000 Subject: [PATCH] fix: add error handling for incorrect profile name --- modules/attachment/main.tf | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/attachment/main.tf b/modules/attachment/main.tf index a1a27c5..a201722 100644 --- a/modules/attachment/main.tf +++ b/modules/attachment/main.tf @@ -35,8 +35,10 @@ locals { ] ) + validate_profile_name = length(local.sorted_list) == 0 ? tobool("Could not find a valid profile name ${var.profile_name}") : true + # Retrieve profile with the latest version by getting last element in sorted list - latest_profile = local.sorted_list[length(local.sorted_list) - 1] + latest_profile = local.validate_profile_name ? local.sorted_list[length(local.sorted_list) - 1] : null profile_map = var.profile_version == "latest" ? { (var.profile_name) = local.latest_profile @@ -46,9 +48,9 @@ locals { } # tflint-ignore: terraform_unused_declarations - 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 + 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 - profile = local.validate_profile ? local.profile_map[var.profile_name] : null + profile = local.validate_profile_version ? local.profile_map[var.profile_name] : null } data "ibm_scc_profile" "scc_profile" {