Index() function returns item not found - Call to function "index" failed: item not found

Terraform Version
$ terraform -v
Terraform v0.15.4

Terraform Configuration Files

module “policyset_definitions” {
source = “./modules/policyset-definitions”

depends_on = [module.policy_definitions]

policy_def_set_name = var.policy_def_set_name
policy_def_type = var.policy_def_type
policyset_definition_category = var.policyset_definition_category

custom_default_nsg_policies = [
policyID = module.policy_definitions.policy_defination_ids[index([module.policy_definitions.policy_defination_ids], [for i in [module.policy_definitions.policy_defination_ids]: i])]

Debug Output

│ on line 32, in module “policyset_definitions”:
│ 32: policyID = module.policy_definitions.policy_defination_ids[index((var.policy_name),[for i in var.policy_name: i])] #each.key)]
│ ├────────────────
│ │ var.policy_name is list of string with 13 elements

│ Call to function “index” failed: item not found.

Hi @devendrawagh,

Can you say a little more about what you were trying to achieve with this expression? It’s a pretty complicated combination of operations and so I’m not sure what your goal was in order to suggest how to get there.