{"action":"created","issue":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/1604","labels_url":"https://api.github.com/repos/hashicorp/terraform/issues/1604/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/terraform/issues/1604/comments","events_url":"https://api.github.com/repos/hashicorp/terraform/issues/1604/events","html_url":"https://github.com/hashicorp/terraform/issues/1604","id":69687698,"number":1604,"title":"Support use cases with conditional logic","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},"labels":[{"url":"https://api.github.com/repos/hashicorp/terraform/labels/core","name":"core","color":"cccccc"},{"url":"https://api.github.com/repos/hashicorp/terraform/labels/enhancement","name":"enhancement","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":17,"created_at":"2015-04-20T21:38:59Z","updated_at":"2015-05-30T15:16:21Z","closed_at":null,"body":"It's been important from the beginning that Terraform's configuration language is declarative, which has meant that the core team has intentionally avoided adding flow-control statements like conditionals and loops to the language.\r\n\r\nBut in the real world, there are still plenty of perfectly reasonable scenarios that are difficult to express in the current version of Terraform without copious amounts of duplication because of the lack of conditionals. We'd like Terraform to support these use cases one way or another.\r\n\r\nI'm opening this issue to collect some real-world example where, as a config author, it seems like an `if` statement would really make things easier.\r\n\r\nUsing these examples, we'll play around with different ideas to improve the tools Terraform provides to the config author in these scenarios.\r\n\r\nSo please feel free to chime in with some specific examples - ideally with with blocks of Terraform configuration included. If you've got ideas for syntax or config language features that could form a solution, those are welcome here too.\r\n\r\n(No need to respond with just \"+1\" / :+1: on this thread, since it's an issue we're already aware is important.)"},"comment":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/comments/107052018","html_url":"https://github.com/hashicorp/terraform/issues/1604#issuecomment-107052018","issue_url":"https://api.github.com/repos/hashicorp/terraform/issues/1604","id":107052018,"user":{"login":"bortels","id":199865,"avatar_url":"https://avatars.githubusercontent.com/u/199865?v=3","gravatar_id":"","url":"https://api.github.com/users/bortels","html_url":"https://github.com/bortels","followers_url":"https://api.github.com/users/bortels/followers","following_url":"https://api.github.com/users/bortels/following{/other_user}","gists_url":"https://api.github.com/users/bortels/gists{/gist_id}","starred_url":"https://api.github.com/users/bortels/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bortels/subscriptions","organizations_url":"https://api.github.com/users/bortels/orgs","repos_url":"https://api.github.com/users/bortels/repos","events_url":"https://api.github.com/users/bortels/events{/privacy}","received_events_url":"https://api.github.com/users/bortels/received_events","type":"User","site_admin":false},"created_at":"2015-05-30T15:16:21Z","updated_at":"2015-05-30T15:16:21Z","body":"Expanding on the referenced aws spot instances - I'd like to be able to express \"spin up N instances in at least M availability zones, bidding the current bid price * X, But fallback to on-demand for any az where the bid price is > Y, or spot instance is unavailable\". That seems complex (I have implemented it via a custom ruby script now), so maybe it's less a \"we need conditionals\" argument and more a \"it would be nice if the aws provider abstracted instance types and did the \"right thing\"). \r\n\r\nMaybe the whole conditional thing could be handled by some sort of \"call to external\" hook to work the logic? It's a cop-out, in a way, but perhaps the most flexible in the end. If the suggested \"when\" could call an arbitrary script, with current context, you could kinda wedge in anything you needed as a shim, in only the spots where declarative is problematic. Can terraform do external calls like that already? I came into this from the side googling for spot instance solutions and seeing if terraform had support, so I'm not super familiar with current functionality there. "}}