Hello team,
I am facing the issue while using conditional expression in one of the resource.
22 resource "openstack_compute_instance_v2" "instance_i1_image" {
23 name = "${local.instance_name}_${count.index}"
24 image_id = var.image_id
25 flavor_id = openstack_compute_flavor_v2.compute_flavor.id
26 key_pair = openstack_compute_keypair_v2.keypair_k1.id
27 security_groups = [module.neutron.security_group_id]
28 availability_zone = ((var.unique_host == true) && (var.instance_count == length(var.az_host))) ? tostring(var.az_host[0]) : "abc" #<=======
29 network {
30 uuid = module.neutron.internal_network_id
31 }
32 count = var.boot_from_volume ? 0 : var.instance_count
33 }
In above resource availability_zone = ((var.unique_host == true) && (var.instance_count == length(var.az_host))) ? tostring(var.az_host[0]) : "abc"
always set to abc
. It means, the condition(((var.unique_host == true) && (var.instance_count == length(var.az_host)))
) returns false and hence, it returns “abc” value.
But, if I evaluate the same condition through terraform console
, I am getting correct result:
$ terraform console
> ((var.unique_host == true) && (var.instance_count == length(var.az_host))) ? tostring(var.az_host[0]) : "abc"
nova:compute01-617163.localdomain
Here are the values set for the respective variables:
$ cat terraform.tfvars
[…]
instance_count = 2
unique_host = true
az_host = [“nova:compute01-617163.localdomain”,“nova:compute01-617163.localdomain”]
[…]
Am I missing anything here? Can anyone please help me with it.
Thanks in advance.
Kind regards,
Pratik.