-
Notifications
You must be signed in to change notification settings - Fork 117
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
Could we generate random results at plan time rather than apply time? #121
Comments
This would resolve an issue with using |
This issue started happening to me with AWS EKS. Terraform v1.3.7
│ Error: Invalid for_each argument |
There is a growing satellite of higher 👍 downstream resource issues, e.g. hashicorp/terraform-provider-aws#19583, that would benefit from this enhancement. While there may be somethings those downstream resources could do to help prevent problems, if they're using terraform-plugin-sdk, they are limited in their abilities to handle the situations appropriate because that SDK tends to hide or abstract value details in unfortunate ways. Especially in larger providers that will take a long time to migrate completely to terraform-plugin-framework, let alone have practitioners upgrade to those migrated resources, we probably should handle this here as it may be a quicker path to resolution for some practitioners. One holdup from before was that this provider was also using terraform-plugin-sdk, which was awkward to work with in these situations. It's now been migrated to terraform-plugin-framework. I'm queuing this up for maintainer discussion today although I cannot guarantee any particular implementation timeline. |
Seconding calculating random values at apply |
@apparentlymart and @bflad I have started a WIP pull request to implement generating the id for the
I have attempted two things to potentialy save the initial generated id for the second run to use:
Neither of these methods seem to keep the value around for the second run. From the return values of the |
I'd like to see an option to generate the value at plan. I have a troubleshooting case where I'd like to use the random output in a map key fed to A |
Hi all! I was away from this for a long time due to working on other things, but encountered a new instance of this problem today so came back to see if anything new was here! @brittandeyoung, I think what you've found here is indeed an important blocker for what I was considering when I wrote this issue. Terraform Core doesn't currently let providers refer back to their initial plan when building the final plan, instead expecting them to be able to reconstruct the same results from the final configuration. I think when I originally wrote this up I was thinking about the resource types that support specifying a fixed seed, like The Given all this, I don't think what I described in this issue is really actionable right now. It would require, as @brittandeyoung noted, some way to preserve at least some additional information between the initial plan and the final plan, which would require a change to the provider protocol and thus to Terraform Core. |
We have also the same issue. We are trying to create semi Auto-Scaling group in our Cloud provider and we have just discovered that |
I ran into this while using This is my workaround BTW, might be helpful for somebody in the future:
|
When I originally proposed the
random
provider we didn't have any well-defined mechanism for a provider to generate attribute values at any time other than apply time, but in the meantime we have introduced facilities for providers to be able to populate attribute values at plan time, as long as what they are populating exactly matches what will eventually result from apply.For resource types like the ones in this provider, where the primary way to use them is to derive other resource configurations from them, it's helpful to have as much as possible populated with known values during planning so that more values from the rest of the configuration can also be known and visible in the plan output, rather than
(known after apply)
.Given that the
random
provider is originating all of its results in-process rather than via remote APIs, it seems plausible that it should be able to do the random number generation during the plan phase rather than during the apply phase, and then have the apply phase just commit to the state whatever random result the plan phase chose.In principle we have the necessary building blocks in place in the current SDK to implement this, but I know that folks working on other providers have indicated that the
CustomizeDiff
API is hard to use robustly, so it might end up being better to wait until this provider is using a next-generation SDK with a more robust plan customization hook. I'm recording this here now mainly to register the potential use-case as something we might consider when designing that next-generation SDK, although it could also be interesting to prototype this against the legacy SDK and see whether it's robust enough to ship.The text was updated successfully, but these errors were encountered: