Open rschmied opened 1 year ago
Hi @rschmied 👋 Thank you for reporting these issues and sorry you are running into this unexpected behavior.
In an attempt to immediately unblock you, can you try removing the UseStateForUnknown()
plan modifiers from the lab group nested attributes? This should at least prevent the framework logic from causing your plans to raise the Provider produced inconsistent result after apply
Terraform error. There a few considerations the maintainers will need to work through to determine if a fix can be made for the underlying issue without breaking compatibility or if plan modifiers such as UseStateForUnknown()
will need to raise an implementation error diagnostic to prevent their usage when under a list/set.
After some initial investigation, it appears the following setup is problematic:
UseStateForUnknown()
)schema.ListNestedAttribute
, schema.ListNestedBlock
, schema.SetNestedAttribute
, or schema.SetNestedBlock
For the Terraform core panic you mention, I have created a small reproduction and submitted a bug report to Terraform core. It is always invalid for a provider to attempt to set a known configuration value to unknown in a plan response. The framework doesn't have guardrails to raise its own error in this situation and Terraform core is currently raising a panic instead of a proper error (which will be the fix over there). Depending on the clarity of the future Terraform core error, the maintainers here can make a determination whether the framework should implement duplicate detection logic to raise a potentially clearer error.
Thanks for looking into this -- I am currently on PTO and will try your proposed workaround when I am back.
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'm reopening this to signify that the maintainers were not able to rectify the second half of the changes needed before releasing v1.3.0 soon, so v1.3.0 will work with the same (potentially confusing) behavior as before. The hope is that this can be fully addressed in a subsequent release, but there is no timeline yet for that effort.
Module version
Relevant provider source code
Terraform Configuration Files
Debug Output
Expected Behavior
Running with this configuration and removing one of the groups from the set should update the state to reflect the groups set change.
Actual Behavior
The update happens OK on the backend, the API returns all the right elements in the
groups
set (1 element) but it's a 50/50 chance that the state still has the other value.My test removes the element with the ID
cml2_group.group1.id
from the set. When it fails, the resulting error isApparently, the remaining element in the state/set is still the one that was removed from the HCL (and which does not appear in the element returned from the API). It's entirely possible that I do something wrong here as I was working with Lists before but had to move to Sets because of element order etc. As a workaround and in an attempt to mitigate / isolate the error, I added a
SetUnknown
toModifyPlan
like so:When I add the above code, Terraform crashes:
Steps to Reproduce
Testing this requires the provider to talk to some on-Prem software -- so, it's kind of difficult to reproduce without access to said software. It's entirely possible that the code does something utterly stupid. However, setting the Set to Unknown should NOT crash Terraform.
References