-
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
How to set undefined value #5471
Comments
I could really use this too. So I can't write modules that allow either static or dynamic addresses. It's one or the other. |
Very interested in having the ability to set undefined variables. I am in the process of writing modules now, and it would be nice to be able to set optional values as undefined by default so that the module could contain everything the resource has to offer by default but not pulled in if it wasn't necessary. |
Most resources at the moment must just be written to accept some "zero" value as unset. If a resource doesn't support this please report a bug. We hope that in time we'll have a way to unset a value but at the moment we do not. |
I'm curious... if this functionality does not currently exist and you do hope to implement it one day, then why close this issue? I ask out of curiosity rather than frustration. Is the reason that Hashicorp prefer only to use GitHub issues for tracking features that can be placed somewhere on the short-term roadmap rather than the long-term road map? If so, is there any place to record longer-term feature requests? Or is there no attempt to capture these feature requests because Terraform itself is moving so rapidly? |
Resurrecting this conversation.
What are the "zero" - unset values for the parameters ? For example I would like to know the "zero" values for the resource I would like to have a module that allow either an So something along there lines.
If some of the parameters have precedence (example: |
Hi, Following option I tried, but doesn't help me. Any help greatly appreciated main.ft file contains followingresource "azurerm_network_interface" "nic" { variable.tf file contains followingvariable "backend_pool_ids" {} environment.tfvars file contains followingbackend_pool_ids = "" |
So, I'm trying to develop some really dynamic modules, and there are SO many variables which do not support this "zero" to unset concept, and some elements in terraform that should actually accept 0 because 0 is a valid value for that parameter. This approach and the reason this bug was closed doesn't make sense, are we, the community supposed to go open 100 different bugs for each variable we run into (I've found 5 casually just now in addition to the 5 bugs linked above) and just get them fixed as we need them? This seems extremely retroactive and pessimistic of a design. I don't understand why we can't have something similar to...
I'm seeing a recurring theme in my almost two years of using terraform, that something like this above is absolutely necessary to create modern modules without having to create tons of different messy optional count-based resources with all the different types of optional values I might or might not set that don't suppor this "0 unset" concept. Would love some further thinking and feedback on this topic please. Especially with the recent terraform module registry going live, something like this is becoming more and more critical to implement (just like getting Nuances (aka, Flaws) like this really drive my clients away from wanting to adopt Terraform. Because of this flaw, I'm having to maintain multiple slightly modified copies of the same module. Anytime that is necessary usually indicates there is something wrong with the tool/language I'm using. |
i agree with @AndrewFarley - feel like hashicrop is trying to 'manage' the not-so-good feedback that counterfeits the initial hype of the tool we talk about. |
I can't understand how this was closed. At present it is impossible to pass undefined vars into modules. E.g. my module wants to pass some variable It's really frustrating that issues like this seem to keep getting closed. It's like Hashicorp just doesn't want to hear about it and would rather put their fingers in their ears and assume it isn't their problem. Imagine this were a programming language. It's like saying you don't want null or option types and everyone should pass around magic strings and numbers to indicate no value, and everyone should check for those values on their own, rather than having the language provide a feature. It is forcing everyone to do a check over and over again when it should really just be done once within TF. TF should not force you to pass variables around when they are undefined. That's just downright silly. If you make providers fix this, it becomes a neverending battle of trying to get every provider to implement a fix for this quirk. |
Yeah, welcome to the club @mattolenik With modules being at the forefront of the future of Terraform, absolutely this is one of those pivotal "duh" moments where we need the language to evolve to support this. Anytime I do anything even remotely advanced with Terraform I run into this bug and it frustrates the hell out of me. Right now for one client I'm justifying having to have 3 versions of the same module in increasingly "creative" ways because of this bug. Can we raise a bounty to fix this or something? What will it take? :P |
I understand it not being implemented just yet, and that's okay. What bothers me is why these keep getting closed. |
This is also affected by this: hashicorp/terraform-provider-aws#2063 Assuming "-1" for a null value is just insane. This isn't even something providers CAN fix because -1 is a valid value, so there's no way to tell if it's "null" or not. |
I've had exactly the same issues. IMO we need to be able to write real code to define the graph. Either using a new terraform-specific configuration language, or some kind of HCL templating that is closed over the variables and data sources, or give up on HCL-json compatibility and extend HCL, or some other idea. Is there a feature roadmap or RFC where this is atleast being thought about? I understand terraform is still young and things take time to mature, but I'm worried that the terraform team doesn't think the limtiations of HCL are a problem. When I first started with terraform I remember the hope being that HCL itself would be "kinda basically just json" and 3rd parties would develop HCL-generation tools in front. Well those never really happened in a meaningful way, and IMO since we've been adding piecemeal a mishmash of functions that are incomplete and often unintuitive to use, or pushing the burden onto provider repos as-needed and with uncoordinated semantics. Now with backends and workspaces and data sources and modules, code-generation can't work, if it ever could have. Addressing this is important for adoption. I'm beach-heading terraform within our client, a large multinational, and I'm at the point now where I have to pitch their internal ops department to adopt what i've done (and hopefully buy TF Enterprise!) All the issues with inflexibility in conditionalizing resource arguments impairs that pitch. Perhaps experts (like the gruntwork.io team) can get around the issues through extended trickery. But neither sharp learning curves nor "just write some wrapper scripts" endears. |
@BijeshSamson11 seems like you can asnwer https://stackoverflow.com/questions/48306089/how-do-i-make-a-field-optional-inside-a-terraform-resource if possible? |
I've read it but that was made more than a year ago. |
Having the same problem and needing to maintain several versions of a module to support different use cases just becuase I can't unset optional settings or remove whole configuration blocks within a resource when they should not be present. Really frustrating! Terraform needs to add better support for this if it's to become a mature product, and I do hope so because besides this I like it. But it's just not feasible having to maintain several module versions instead of one dynamic one. @mitchellh When is the team going to prioritize and focus on this? The community is really behind this happening as can be seen by the comments here. |
Same problem here. I need to conditionally set one of two mutually exclusive variables, and could really use a null/undefined value |
@AnthonyWC lol, yeah I didn't say it was a solution. And @mitchellh is notorious for muting threads once he's made a judgement. This is a dead-in-the-water request it appears. My guess is they are trying to solve it globally, probably when the make hcl-terraform v2. |
Ok so one workaround at the resource level via count would be to do something like this:
The 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. |
@AnthonyWC Yeah that's what I'm doing to toggle whole resources in the module and it works well, think it's been mentioned before in the comments here also. Have for example like this
For a module which creates cloudfront dist, r53 records and accompanying acm certs. If you already have a cert created you provide a cert arn in the acm_certificate_arn variable which is optional, so if not provided it will create the required resources. Just showing on of them in the snippet above. The issue for me is not toggling resources, it's about toggling fields and configuration blocks within a resource. The other day we got a use case where a team wanted to use Lambda@Edge. For cloudfront resource that's a specific config block which associates the lambda function with the distribution. I can't have the module always creating this association, only when it's needed. So had to branch out and have that as a separate version. That's one use case, there are many... @apparentlymart @mitchellh Some attention to this, please? |
To the 20 folks who are watching this issue - native null value support is coming in Terraform 0.12! The HCL2 integration effort is well underway. This description from @apparentlymart is from last year but is still mostly accurate in its description of the incoming functionality: #14037 (comment) |
READMEs are part of the standard module structure [1], and docs like this should make onboarding new contributors easier. The example's etcd ports are from [2,3]. The egress rule is based on [4], although I've restricted it to the VPC. I've also added some defaults, so users who are not interested lower-level settings can ignore them. You can find Container Linux AMIs in [5] if you want to test ec2_ami. I've added a dependency on modules/container_linux to get local container_linux_version support for 'lastest'. Without that, even users setting ec2_ami would need to set a major.minor.patch container_linux_version to avoid hitting: * module.etcd.data.aws_ami.coreos_ami: data.aws_ami.coreos_ami: Your query returned no results. Please change your search criteria and try again. Some of the module variables are just passed through to lower-level providers (e.g. ssh_key is passed through to aws_instance's key_name). That sort of thing is awkward at the moment, because there's no generic way to declare a variable unset (vs. setting it to some sort of zero value). Terraform will grow support for that distinction (via a 'null' value) in 0.12 as part of HCL2 [6,7]. Terraform 0.12 is due out in the next few months [7]. The hcl pretty printing is supported by Linguist [8], which GitHub uses for syntax highlighting [9]. [1]: https://www.terraform.io/docs/modules/create.html#standard-module-structure [2]: https://github.com/coreos/etcd/blob/master/README.md#etcd-tcp-ports [3]: http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.txt [4]: https://www.terraform.io/docs/providers/aws/r/security_group.html#argument-reference [5]: https://coreos.com/os/docs/latest/booting-on-ec2.html [6]: hashicorp/terraform#5471 (comment) [7]: https://www.hashicorp.com/blog/terraform-0-1-2-preview [8]: https://github.com/github/linguist/blob/v6.3.1/lib/linguist/languages.yml#L1723-L1733 [9]: https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting
READMEs are part of the standard module structure [1], and docs like this should make onboarding new contributors easier. The example's etcd ports are from [2,3]. The egress rule is based on [4], although I've restricted it to the VPC. I've also added some defaults, so users who are not interested lower-level settings can ignore them. You can find Container Linux AMIs in [5] if you want to test ec2_ami. I've added a dependency on modules/container_linux to get local container_linux_version support for 'lastest'. Without that, even users setting ec2_ami would need to set a major.minor.patch container_linux_version to avoid hitting: * module.etcd.data.aws_ami.coreos_ami: data.aws_ami.coreos_ami: Your query returned no results. Please change your search criteria and try again. Some of the module variables are just passed through to lower-level providers (e.g. ssh_key is passed through to aws_instance's key_name). That sort of thing is awkward at the moment, because there's no generic way to declare a variable unset (vs. setting it to some sort of zero value). Terraform will grow support for that distinction (via a 'null' value) in 0.12 as part of HCL2 [6,7]. Terraform 0.12 is due out in the next few months [7]. The hcl pretty printing is supported by Linguist [8], which GitHub uses for syntax highlighting [9]. [1]: https://www.terraform.io/docs/modules/create.html#standard-module-structure [2]: https://github.com/coreos/etcd/blob/master/README.md#etcd-tcp-ports [3]: http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.txt [4]: https://www.terraform.io/docs/providers/aws/r/security_group.html#argument-reference [5]: https://coreos.com/os/docs/latest/booting-on-ec2.html [6]: hashicorp/terraform#5471 (comment) [7]: https://www.hashicorp.com/blog/terraform-0-1-2-preview [8]: https://github.com/github/linguist/blob/v6.3.1/lib/linguist/languages.yml#L1723-L1733 [9]: https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting
Terraform v12.0 does not have any end date in sight. This issue has been open for 2.5+ years. : [ |
Well, I hope it's gonna be a great 2019 (for me, at least, having this will help make it a better year). |
It's not gonna happen in my life... |
0.12 is out! |
https://github.com/hashicorp/terraform/releases/tag/v0.12.0 --> Solves the problem finally! :-) |
The value is just eg |
But it seems doesn't work as expected :( Just called from the upstream module and passed
|
@mikalai-t Thank you for the report here! I've opened a fresh issue as this looks like a valid bug we should fix. I'm going to lock the conversation here, since the original issue has been closed by the release of 0.12, and I want to make sure we don't lose track of comments on this open issue. |
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:
My 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'sundef
.The text was updated successfully, but these errors were encountered: