{"action":"created","issue":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/5471","repository_url":"https://api.github.com/repos/hashicorp/terraform","labels_url":"https://api.github.com/repos/hashicorp/terraform/issues/5471/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/terraform/issues/5471/comments","events_url":"https://api.github.com/repos/hashicorp/terraform/issues/5471/events","html_url":"https://github.com/hashicorp/terraform/issues/5471","id":138781781,"number":5471,"title":"How to set undefined value","user":{"login":"joshuaspence","id":234676,"avatar_url":"https://avatars3.githubusercontent.com/u/234676?v=4","gravatar_id":"","url":"https://api.github.com/users/joshuaspence","html_url":"https://github.com/joshuaspence","followers_url":"https://api.github.com/users/joshuaspence/followers","following_url":"https://api.github.com/users/joshuaspence/following{/other_user}","gists_url":"https://api.github.com/users/joshuaspence/gists{/gist_id}","starred_url":"https://api.github.com/users/joshuaspence/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshuaspence/subscriptions","organizations_url":"https://api.github.com/users/joshuaspence/orgs","repos_url":"https://api.github.com/users/joshuaspence/repos","events_url":"https://api.github.com/users/joshuaspence/events{/privacy}","received_events_url":"https://api.github.com/users/joshuaspence/received_events","type":"User","site_admin":false},"labels":[{"id":127939292,"url":"https://api.github.com/repos/hashicorp/terraform/labels/core","name":"core","color":"cccccc","default":false},{"id":85946961,"url":"https://api.github.com/repos/hashicorp/terraform/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":29,"created_at":"2016-03-06T10:57:48Z","updated_at":"2018-04-12T18:39:40Z","closed_at":"2016-12-04T00:23:13Z","author_association":"CONTRIBUTOR","body":"I am writing a module for creating EC2 instances. We have a lot of duplication between our EC2 instance configuration (tags, user data, common security groups, etc) and creating a module eliminates code duplication. I am not sure, however, how to set a value to be undefined. For example, suppose that my module looked like this:\n\n```\nvariable \"availability_zone\" {\n  type = \"string\"\n  default = \"\"\n}\n\nresource \"aws_instance\" \"instance\" {\n  availability_zone = \"${var.availability_zone}\"\n}\n```\n\nMy question here is what is the correct default value for the `availability_zone` variable such that it is essential an optional parameter? Empty string seems to work in some cases, but I'm not sure if this would work in all cases? Basically I am looking for the Terraform equivalent of puppet's `undef`.\n"},"comment":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/comments/380904621","html_url":"https://github.com/hashicorp/terraform/issues/5471#issuecomment-380904621","issue_url":"https://api.github.com/repos/hashicorp/terraform/issues/5471","id":380904621,"user":{"login":"AnthonyWC","id":6215805,"avatar_url":"https://avatars1.githubusercontent.com/u/6215805?v=4","gravatar_id":"","url":"https://api.github.com/users/AnthonyWC","html_url":"https://github.com/AnthonyWC","followers_url":"https://api.github.com/users/AnthonyWC/followers","following_url":"https://api.github.com/users/AnthonyWC/following{/other_user}","gists_url":"https://api.github.com/users/AnthonyWC/gists{/gist_id}","starred_url":"https://api.github.com/users/AnthonyWC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AnthonyWC/subscriptions","organizations_url":"https://api.github.com/users/AnthonyWC/orgs","repos_url":"https://api.github.com/users/AnthonyWC/repos","events_url":"https://api.github.com/users/AnthonyWC/events{/privacy}","received_events_url":"https://api.github.com/users/AnthonyWC/received_events","type":"User","site_admin":false},"created_at":"2018-04-12T18:39:40Z","updated_at":"2018-04-12T18:39:40Z","author_association":"NONE","body":"Ok so one workaround at the resource level via count would be to do something like this:\r\n\r\n```\r\nvariable \"optional_resource_parameter\" {\r\n  default = \"default_null\"\r\n}\r\n\r\nresource \"foo\" \"bar\" {\r\n  count = \"${var.optional_resource_parameter == \"default_null\" ? 0 : 1}\"\r\n}\r\n```\r\n\r\nThe trick is to define a default value to represent null and then use count to set to 0 if the default is not changed to anything else.  This still require you to write out multiple version of resource level definition though so it's still not ideal but at least your module can reference the same directory."}}
{"actor":{"display_login":"AnthonyWC"}}