{"action":"created","issue":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/2782","labels_url":"https://api.github.com/repos/hashicorp/terraform/issues/2782/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/terraform/issues/2782/comments","events_url":"https://api.github.com/repos/hashicorp/terraform/issues/2782/events","html_url":"https://github.com/hashicorp/terraform/issues/2782","id":95879593,"number":2782,"title":"improve support for simple math operations in interpolation","user":{"login":"ketzacoatl","id":10122937,"avatar_url":"https://avatars.githubusercontent.com/u/10122937?v=3","gravatar_id":"","url":"https://api.github.com/users/ketzacoatl","html_url":"https://github.com/ketzacoatl","followers_url":"https://api.github.com/users/ketzacoatl/followers","following_url":"https://api.github.com/users/ketzacoatl/following{/other_user}","gists_url":"https://api.github.com/users/ketzacoatl/gists{/gist_id}","starred_url":"https://api.github.com/users/ketzacoatl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ketzacoatl/subscriptions","organizations_url":"https://api.github.com/users/ketzacoatl/orgs","repos_url":"https://api.github.com/users/ketzacoatl/repos","events_url":"https://api.github.com/users/ketzacoatl/events{/privacy}","received_events_url":"https://api.github.com/users/ketzacoatl/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hashicorp/terraform/labels/core","name":"core","color":"cccccc"},{"url":"https://api.github.com/repos/hashicorp/terraform/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-07-19T02:57:59Z","updated_at":"2015-07-27T22:01:44Z","closed_at":null,"body":"The https://terraform.io/docs/configuration/interpolation.html docs note:\r\n\r\n> You can also perform simple math in interpolations, allowing you to write expressions such as ${count.index+1}.\r\n\r\nI guess this works with `count`, but it surely doesn't work with `${var.name-1}` or multiplication/division.. so I think this doc is misleading in what is possible.\r\n\r\nHere is a simple use case: I have a terraform module used in an elastic environment, and each run of the environment may have different storage requirements, so I have variables for the size of docker and data volumes. These variables are first provided to AWS in creating EBS volumes, but they are then seeded into YAML (via Terraform's rendered templates) which configures the fdisk and lvm provisioning done by Saltstack on cloud init.. but because of the nature of LVM, I need to tell those LVM volumes and filesystem to be slightly smaller than the full EBS volume. If I could multiply or subtract a decimal/float, I could easily use one variable in both AWS EBS and the LVM formula and handle the small bit of math needed to properly instruct LVM what to do.\r\n\r\nMaybe there is another or better way?"},"comment":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/comments/125356007","html_url":"https://github.com/hashicorp/terraform/issues/2782#issuecomment-125356007","issue_url":"https://api.github.com/repos/hashicorp/terraform/issues/2782","id":125356007,"user":{"login":"phinze","id":37534,"avatar_url":"https://avatars.githubusercontent.com/u/37534?v=3","gravatar_id":"","url":"https://api.github.com/users/phinze","html_url":"https://github.com/phinze","followers_url":"https://api.github.com/users/phinze/followers","following_url":"https://api.github.com/users/phinze/following{/other_user}","gists_url":"https://api.github.com/users/phinze/gists{/gist_id}","starred_url":"https://api.github.com/users/phinze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phinze/subscriptions","organizations_url":"https://api.github.com/users/phinze/orgs","repos_url":"https://api.github.com/users/phinze/repos","events_url":"https://api.github.com/users/phinze/events{/privacy}","received_events_url":"https://api.github.com/users/phinze/received_events","type":"User","site_admin":false},"created_at":"2015-07-27T22:01:44Z","updated_at":"2015-07-27T22:01:44Z","body":"> I started with something simple.. I have a variable: ${var.name}, and I want to subtract 1. How do I do this?\r\n\r\nSure! Config:\r\n\r\n```js\r\nvariable \"name\" {\r\n  default = \"123\"\r\n}\r\n\r\noutput \"minusone\" {\r\n  value = \"${var.name - 1}\"\r\n}\r\n```\r\n\r\nOutput:\r\n\r\n```\r\n❯ terraform apply\r\n\r\nApply complete! Resources: 0 added, 0 changed, 0 destroyed.\r\n\r\nOutputs:\r\n\r\n  minusone = 122\r\n```"}}