-
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
count parameter needs to be able to interpolate variables from modules. #1497
Comments
👍 Surprised to see I can't do |
+1 |
We should definitely do this, the tricky part comes from the fact that count expansion is currently done statically, before the primary graph walk, which means we can't support "computed" counts right now. (A "computed" value in TF is one that's flagged as not known until all its dependencies are calculated.) Related: #354 So we'd need to rework resource count expansion to occur "just in time" to support this. Probably the right thing to do in the long run, but that's what makes this nontrivial to fix. |
Sounds like I might need to preprocess these .tf files for a little while then. I don't suppose you have a sense of where in the roadmap this rework might happen? |
I have a pretty kludgy workaround for this; I really want a way to store intermediate variables somehow…
Basically, the number of availability zones are determined by the I mean, this is really kludgy, but so far it's working in the demo I'm hacking together today… |
Another usecase I have, is that I want to take advantage of route53's nameserver/load balancer integration, but I use cloudflare for everything else. So what I want to do is to create a new cloudflare NS record for each route53 nameserver. Luckily we know there are 4 nameservers in the list that route53 gives back, so you can hardcode the count in like so:
|
👍 I've been trying to pass counts down to modules either directly or through |
Am blocked by this as well. I want to be able to have AWS "datacenter_a" and "datacenter_b" modules parameterized by AWS region, and set count to the number of availability zones in the provided region. Currently hitting the "strconv.ParseInt" error and am forced to simply hardcode the count to "2". |
+1 |
I ran into this issue this morning and our previous hack doesn't seem to work anymore. Our hack had consisted of what we called "priming" the counts. We had a module which outputted a count which we then used to input into another module for a resource's count. We'd only run into this issue on clean state, that is, nothing yet created. So what we'd do is create an override with the outputs defaulted to zero, run a terraform plan, remove the override and things were ok. It'd then continue to use the module output correctly as it was updated, but that no longer works. For now, I believe we're going to find another workaround in which we'll probably just have to set the count in two different places, but it would be great to have this resolved. |
+1 |
Also just bumped into this when trying to modularize my VPC design. Would be useful to have this support |
+1 |
3 similar comments
+1 |
+1 |
+1 |
+1 |
+1 |
This will help me fix about 20 lines in my terraform project that are essentially
Edit: This was a result of me not realizing I was writing the wrong variable names. |
Like @johnhamelink's issue above, computed counts would help when setting up Mailgun. The Mailgun provider returns DNS records that you're supposed to create, and it would be nice to be able to directly create those after the Mailgun domain is set up. Right now I just have to hard-code that |
Still a problem in
|
Another example of this being an issue is when trying to split the results of data.aws_ip_ranges into groups of 50 or less to be distibuted amongst a number of security groups. having to resort to hard coded lists. not happy. |
i'm getting this error. The variable referenced in the count property is '0' or '1'. (checked via output) when the value is set manually (=0 or =1) everything works properly. Using terraform v0.7.13
So it seems that the problem is not only when interpolating from modules, also from external state. |
Yeah, modules are very limited by this at the moment. For instance, I have a vpc module with public and private subnets that I'd like to be deployable in any aws-region. Users of the module are allowed to have as many subnets as they would like; accordingly, the module takes the number specified and iterates over the az data resource. Later when creating nat instances for the private subnets, that part of the module should be able to take for count something like Alas, these are cool problems to have. Keep up the good work! |
+1 to fix this |
+1 |
+1 Would very much love to hear an update on this issue. The "count bug" as I call it is limiting me all over my TF build.
Over and Over. |
Got into this again. I would like to be able to do
It works fine if I declare count to be e.g |
👍 |
1 similar comment
+1 |
This disables the computed value check for `count` during the validation pass. This enables partial support for #3888 or #1497: as long as the value is non-computed during the plan, complex values will work in counts. **Notably, this allows data source values to be present in counts!** The "count" value can be disabled during validation safely because we can treat it as if any field that uses `count.index` is computed for validation. We then validate a single instance (as if `count = 1`) just to make sure all required fields are set.
This should be fixed by #11482. Blanket support for computed values is still not allowed since it doesn't allow a deterministic "plan" to happen. However, you can now use data source values as an input to count (which was one of the reasons for this in the first place) with #11482. There are still plans to improve this further and potentially allow any computed value in "count" by splitting plan/apply into multiple distinct steps. However, I think that allowing data sources will be a big big step forward and bring a lot more functionality to count. |
Will this be backported to 0.8.x too? |
It will not |
Fixed by #11482! See that issue for caveats, though I think you'll find them acceptable. |
…and also that several workarounds formerly attributed to hashicorp/terraform#1497 are actually more closely related to hashicorp/terraform#4149 (and are still necessary for greenfield VPC construction since the value used in count comes from a resource created by Terraform)
I think I just came across an example that I would have expected to work under this (as to my mind it is deterministic but I get the "value of 'count' cannot be computed" error: If I have this in a module:
And then the call site:
Even If I change it to use an extra
I get the same error. The only way I could make it work was to remove one level of indirection:
(The public_subnet from the vpc module creates one subnet per AZ given.) |
Hi @ashb, That does seem strange. Would you mind opening a new top-level issue for that? It seems like something more subtle than what this issue was about. If you do open a new issue, it would be helpful to also see the relevant contents of your |
@apparentlymart Thanks, reported with repro as #14677 |
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. |
I've been trying to extend my Terraform examples to support multiple AZs by default.
As such, I have an az_count variable output by my module to detect the AZs you have available:
https://github.com/terraform-community-modules/tf_aws_availability_zones#outputs
And I then want to reuse it for instances, for example here:
https://github.com/bobtfish/terraform-vpc/blob/master/main.tf#L37
My example (https://github.com/bobtfish/terraform-example-vpc/tree/master/eucentral1-demo) crashes out with the error:
and if I remove this error from the source (hope springs eternal!), I run into:
This inability to interpolate count variables is a blocker for me being able to write region independent modules - as (for example) I want to be able to allocate one subnet per AZ, writing code like:
Even better, I'd like to be able to interpolate variables out of one module, and into the user variables of another, for example:
The text was updated successfully, but these errors were encountered: