-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Invalid calculation result together with floor/ceil #29301
Description
We faced a strange bug that prevents us from upgrading from Terraform v0.15.4 to v1.0.3.
With v0.15.4 we can't reproduce the bug, with v1.0.3 we can. So the bug was introduced after v0.15.4.
EDIT: See my comment, bug seems to be there since v1.0.2
Imho it is a critical one as it leads to unexpected behavior for each apply.
Terraform Version
Terraform v1.0.3
on linux_amd64
Terraform Configuration Files
locals {
val = 64 - 4
val2 = floor(local.val)
}
output "val" {
value = local.val
}Expected Behavior
Output val should have the exact value 60.
Actual Behavior
Sometimes the output val has the value 60, sometimes it has a lot of decimals, e.g. 60.00000000000000000325260651745651330202235840260982513427734375
Steps to Reproduce
Call terraform apply -auto-approve multiple times, the output val will have different values.
If you remove the line val2 = floor(local.val) the output val will be stable. Thus it seems that the local val will somehow be changed when using floor (or ceil) on it.. I would expect the local is constant and can't be changed by some other expression.
You can also change val to val = 64 (remove the subtraction) and then it keeps stable. So substracting numbers and then using floor/ceil seems to make trouble.