-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Add math support to embedded interpolation language #1068
Conversation
Ready for review as best as possible @phinze. I don't expect you'll have to see this area of the code much, but could be useful to see how something like this is added. :) |
result *= arg | ||
case ast.ArithmeticOpDiv: | ||
result /= arg | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"You don't get fload mod, because if you need float mod in your terraform config, you're doing something very wrong."
^^ This the logic? Sounds about right to me. 😏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, float modulus doesn't make sense or even work (syntax error in Go).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well there is http://golang.org/pkg/math/#Mod but the logic still stands
Add math support to embedded interpolation language
Document the fix to GH-1068 on the website
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. |
Fixes #686
This adds basic arithmetic to the embedded interpolation language: add, subtract, multiply, divide, modulo for both ints and floats (except mod for floats, of course). This lets you do fancy things like
${count.index+1}
. The changes made in this PR:+, -, *, /, %
)expr OP expr
and'(' expr ')'
(for orders of operations).