Lookup(vm_info, "vm_count", 1) returns a string as default value

Hi everyone,

I’m facing a very strange behavior with lookup() function which, sometimes, returns a string rather than an integer as default value which is an integer (no quotes).

In that code, it returns “1” and not 1, I had to add a second condition.

  srv_list = flatten([
    for net_info in local.vm_net_list : [
      for vm_name, vm_info in net_info.srv_list : [
        for vm_index in range(lookup(vm_info, "vm_count", 1)) : {
          vm_name             = lookup(vm_info, "vm_count", 1) == 1 || lookup(vm_info, "vm_count", 1) == "1" ? format("%s_%s", net_info.obj_prefix, vm_name) : vm_index < 10 ? format("%s_%s0%s", net_info.obj_prefix, vm_name, vm_index + 1) : format("%s_%s%s", net_info.obj_prefix, vm_name, vm_index + 1),
          vm_count            = lookup(vm_info, "vm_count", 1),

In that case, no need to add a second condition as lookup() returns 1 (when no value “vm_count” is found).

  rtr_list = flatten([
    for net_info in local.vm_net_list : [
      for vm_name, vm_info in net_info.rtr_list : [
        for vm_index in range(lookup(vm_info, "vm_count", 1)) : {
          vm_name             = lookup(vm_info, "vm_count", 1) == 1 ? format("%s_%s", net_info.obj_prefix, vm_name) : vm_index < 10 ? format("%s_%s0%s", net_info.obj_prefix, vm_name, vm_index + 1) : format("%s_%s%s", net_info.obj_prefix, vm_name, vm_index + 1),
          vm_count            = lookup(vm_info, "vm_count", 1),

Believe me or not, I’m puzzled : )

the variable declaration does not force any type as the definition is the following:

variable "vm_net_list" {
  type = map(object({
    vlan_id              = number,
    vSwitch              = string,
    cidr                 = string,
    srv_gateway_ip       = number,
    rtr_list = map(any),
    srv_list = map(any)
  }))
  description        = "The list of LANs and their VMs"
  default            = null
}

Any idea of what I missed?

Best regards,

mathias