Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid calculation result together with floor/ceil #29301

Closed
chris922 opened this issue Aug 4, 2021 · 4 comments · Fixed by #29406
Closed

Invalid calculation result together with floor/ceil #29301

chris922 opened this issue Aug 4, 2021 · 4 comments · Fixed by #29406
Labels
bug config confirmed a Terraform Core team member has reproduced this issue upstream

Comments

@chris922
Copy link

chris922 commented Aug 4, 2021

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.

@chris922 chris922 added bug new new issue not yet triaged labels Aug 4, 2021
@chris922
Copy link
Author

chris922 commented Aug 4, 2021

I just downloaded TF v1.0.1 and v1.0.2 and the bug should be there since v1.0.2. With v1.0.1 everything seems to be fine.

@jbardin jbardin added config confirmed a Terraform Core team member has reproduced this issue upstream and removed new new issue not yet triaged labels Aug 4, 2021
@jbardin
Copy link
Member

jbardin commented Aug 4, 2021

Thanks for the reproduction case @chris922!

Reported upstream in zclconf/go-cty#114

@chris922
Copy link
Author

@jbardin : Thanks a lot for the fix. What is the usual approach with bugs in other libraries? As the PR was merged in go-cty project, will this dependency updated directly or is there a new go-cty release required? The last one was in 2020, so I don't know about the release train there.. hopefully it will not take a long time until they do a bugfix release.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug config confirmed a Terraform Core team member has reproduced this issue upstream
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants