-
-
Notifications
You must be signed in to change notification settings - Fork 221
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
The "for_each" value depends on resource attributes that cannot be determined until apply #59
Comments
This is, unfortunately, the valid behavior of Terraform still. You even gave Terraform a hint by using |
I can also confirm, I have the same issue after upgrade from 1.11.0 version to 2.3.0. main.tf
Receive output:
When I replace in 2.3.0 two strings from 1.11.0 it works correctly |
It's worth noting that the |
Also facing this issue. on .terraform/modules/records/modules/records/main.tf line 32, in resource "aws_route53_record" "this":
│ 32: for_each = var.create && (var.zone_id != null || var.zone_name != null) ? local.recordsets : tomap({})
│ ├────────────────
│ │ local.recordsets will be known only after apply
│ │ var.create is true
│ │ var.zone_id is "<redacted>"
│ │ var.zone_name is null
│
│ The "for_each" value depends on resource attributes that cannot be
│ determined until apply, so Terraform cannot predict how many instances will
│ be created. To work around this, use the -target argument to first apply
│ only the resources that the for_each depends on. downgrading to |
We had success downgrading to |
That is very useful @whiteley! So looks like |
Probably, it is related to I don't know the answer myself. If anyone has a working solution, please open a PR, and let's try to get it to work for terragrunt and terraform users. |
I suspect it's because terraform is deferring the processing of jsondecode to be an "impure function" as their evaluation is deferred until the main evaluation step (after plan?)
https://www.terraform.io/docs/language/meta-arguments/for_each.html#limitations-on-values-used-in-for_each (https://www.terraform.io/docs/language/meta-arguments/for_each.html#limitations-on-values-used-in-for_each)
… for_each keys cannot be the result (or rely on the result of) of impure functions, including uuid, bcrypt, or timestamp, as their evaluation is deferred during the main evaluation step.
|
I'm not sure if this is a use case for a |
Just dropping in to say I do not believe it is specific to |
Seem issue here. Will this will be fixed? |
Is this going to be fixed anytime soon? |
I am not sure how to fix this. If anyone has a possibility to look into this, please open a PR where this is implemented correctly for all cases (to begin with, |
Maybe we should fallback to |
|
Confirmed on terragrunt. Removing the |
I would like to suggest a possible solution and I have prepared a draft PR #64. When any attribute of a record depends on resources that have to be created, The idea of the proposed solution is to allow the caller of the records module to pass to it, in another variable, a list with fully-known keys that the module can use for its internal map. This list, with fully-known keys, allows Terraform to build the plan. |
This issue has been automatically marked as stale because it has been open 30 days |
I can confirm that old v2.0.0 works great. |
Ran into this right now as well, on |
I reverted this commit on Working code:
|
This issue has been automatically marked as stale because it has been open 30 days |
It sounds like a pretty good workaround for the current error. Not being able to use this Terraform module because of Terragrunt miscompatibility is pretty weird. |
just trying to understand these two modules(zones and records)can this handle multiple zones and how do you map records to the respective zones. |
module route53/records - can't create DNS records using
|
Same issue with other resource dependency. It start to work only after resource Base code
Resource - ok
Module - issue
Error
|
Same problem I have downgrade to version 2.0.0. |
This issue has been automatically marked as stale because it has been open 30 days |
any update on this please? thanks |
@vtzan Not yet. Hopefully, during this week, it will be improved. |
Great news! Thank you @antonbabenko for your reply |
@antonbabenko There was a proposed solution in PR #64, but that PR has been closed automatically due to staleness. Just a gentle reminder about it, in case there isn't a better solution. |
@vtzan I give up (for at least a couple of months). I tried to fix it for several hours more, involving @bryantbiggs, but it is still not working as we need. I opened #72 and added the explanation for anyone willing to give it a try. @flora-five #64 is rather close, but I am not sure it is going to work with all examples. Also, it would be great if it did not introduce a new unnecessary/verbose variable (record_map_keys). |
This issue has been resolved in version 2.8.1 🎉 |
Please give it a try! Big thanks to @flora-five for the final touch that fixed the unfixable :) |
Dear @antonbabenko @flora-five this is working great! Thanks alot for the fix. |
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. |
Description
Hello. When using the latest module version and running the plan to create a record based on the value of a CloudFront distribution created using a for_each:
The plan fails with the following error when running locally or on Terraform Cloud:
Versions
Reproduction
Steps to reproduce the behavior:
Code Snippet to Reproduce
Additionally to the above code, this is the extra relevant part:
main.tf
varaibles.tf
Expected behavior
The plan should end successfully.
Actual behavior
The error is shown in the "plan" state and thus the apply is impossible.
Terminal Output Screenshot(s)
Workaround
On local backend, the
-target
argument can be used to first plan and apply the dependencies. On Terraform Cloud there is theTF_CLI_ARGS_plan
environment variable, which is supported since version 0.13, e.g.:TF_CLI_ARGS_plan="-target=module.cloudfront"
Additional context
When first creating the AWS CloudFront dependency, then the records can be planned correctly, as the resources now exists. But running per parts is not ideal.
The error is about "
local.recordsets will be known only after apply
". I wonder if it is possible to have this refactor to avoid thefor_each
issue, or if this is a deeper rooted Terraform limitation?terraform-aws-route53/modules/records/main.tf
Lines 15 to 20 in 533f07d
Thanks.
The text was updated successfully, but these errors were encountered: