Lenght of array[null] will return 1
For example:
module foobar
resource "azurerm_lb" "lb" {
...
# there will be 0 or 1
count = 0
}
output "lb_ip" {
value = [azurerm_lb.lb[0].private_ip_address]
}
main.tf
output "length" {
value = length(module.foobar.lb_ip)
}
output length will return 1 ( it will count null
as element )
I tried:
length(compact(module.foobar.lb_ip))
and
length([compact(module.foobar.lb_ip)])
even
length(concat(compact(module.foobar.lb_ip),[]))
, but witout success.
Any idea? Length should be 0 or 1 in case of azurerm_lb
will be created.
Thanks
EDIT:
output "lb_ip" {
value = concat([azurerm_lb.lb[0].private_ip_address],[])
}
will return:
b = [
null,
]
output "lb_ip" {
value = value = "${element(concat(azurerm_lb.lb.*.private_ip_address, list("")), 0)}"
}
will return:
b = ""
what is difference?
Will I be limited with this https://github.com/hashicorp/terraform/issues/17862 ?
Seems there is missing something like azurerm_lb.lb[0].private_ip_address is defined ? "foo" : "bar"