Closed adam-rummer-hpe closed 3 months ago
Hi @adam-rummer-hpe,
The sort
function is defined as taking a list(string)
and returning a list(string)
. Therefore when you call sort(local.a)
, Terraform implicitly converts this tuple([string, string, string])
value into list(string)
before passing it to the function, and then the result is list(string)
.
That means that your output value sorted
is comparing a tuple([string, string, string])
value to a list(string)
value, and that will always return false because two values can be equal only if they have the same type.
I expect you can achieve the result you wanted by setting local.a
to also be a list(string)
value, by forcing conversion to a list type:
locals {
a = tolist(["a", "b", "c"])
}
Once local.a
is also a list(string)
value, local.a == sort(local.a)
should produce true
as you wanted.
Please let me know if that doesn't work!
Got it, thanks very much @apparentlymart :)
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Terraform Version
Terraform Configuration Files
Debug Output
https://gist.github.com/adam-rummer-hpe/fb3629195481d99879099950992f36e5
Expected Behavior
when already sorted, the list should be equal to the sorted list
Actual Behavior
they are not evaluated as being equal, despite outputting the same
e.g. a plan produces
Steps to Reproduce
terraform init
terraform plan
Additional Context
No response
References
No response