-
Notifications
You must be signed in to change notification settings - Fork 91
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
Two computed values on a resource with one planmodifier results in unexpected new value #615
Comments
Hi again @mvantellingen 👋 The direct reason for the Terraform error is because the generated plan is:
The If it is known that this particular attribute value will always be incremented by one during in-place updates, a plan modifier can be added that signals to the resource plan (and any potential downstream references to that attribute) about the expected value change. This would prevent downstream references from also showing unknown (known after apply) in plans. Having something like this in place would hopefully override whatever the framework is missing in this case to prevent the original error. |
What's strange in this case is that the
Which does indeed match the plan UI output. This may be due to the fact that the only proposed change is to an Optional+Computed attribute, which imposes some special handling in Terraform. I will need to followup with the Terraform maintainers to get some clarifications on the expected behavior here. Updating the Required attribute in the second test step, e.g. {
Config: providerConfig + `
resource "hashicups_order" "test" {
my_boolean = true
my_default_boolean = true
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("hashicups_order.test", "computed_value", "2"),
resource.TestCheckResourceAttr("hashicups_order.test", "my_default_boolean", "true"),
),
}, Does do the correct planning behavior according to the resource definition:
|
I think I narrowed down the internal Terraform plan data logic to the following:
This means that between your two test step configurations, that the entire prior state will exactly match the entire proposed new state (plan). This defeats the framework logic for Computed unknown marking that compares the entire prior state to the entire proposed new state (plan), which occurs before attribute plan modifiers and resource-level plan modification. 😖 This leaves us in a particular bind from a framework perspective. We've held off running attribute/resource plan modification prior to the unknown marking because it could heavily impact how attribute plan modifiers need to be coded (#183). One potential path forward might be to introduce separate, native "default value" handling for attributes, which does run before the unknown value marking. In this situation then, the prior state would mismatch the proposed new state due to the value being updated and therefore the unknown marking would occur. We'll want to followup with the Terraform to ensure our understanding of this situation is correct though first before embarking on that endeavor. All this being said, if you are not able to implement a custom attribute plan modifier that returns a known value while planning in-place updates, then that logic can at least mark the value explicitly as unknown to prevent the Terraform error, similar to what the framework should've already done. |
Hi @bflad, thanks again for the detailed analysis. Really interesting to read. My take is that it indeed errors incorrectly when the only change in the plan is that of a computed/optional value.
It is unfortunately not a known computed value, and I don't want to take assumptions there since the remote API should be the source of truth for this value.
I created a modifier for the I'll see if I can stop using the modifiers for default values for now and if there are other workarounds there. |
This should be covered by #668, which introduces new resource default value handling before the unknown marking, which will release with terraform-plugin-framework version 1.2.0 🔜 . If there are further bug reports, feature requests, or documentation suggestions with resource default value handling, please raise a new issue. 👍 Otherwise if the use case is not fully covered, #605 may be helpful here. |
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. |
Module version
Relevant provider source code
See the repository at https://github.com/mvantellingen/terraform-pf-testcase/tree/computed-atts for reproducing the issue. Resource schema defined at https://github.com/mvantellingen/terraform-pf-testcase/blob/computed-atts/hashicups/order_resource.go#L53
Expected Behavior
The end-goal here is to implement default values. In this case the
my_default_boolean
should always default to false since that is the default for the endpoint. This might also be a different primitive value.Actual Behavior
When running the test I receive the following error:
ComputedValue here is a dummy value. In the real scenario it is a version identifier that gets increment with each change in the remote resource.
Steps to Reproduce
git clone https://github.com/mvantellingen/terraform-pf-testcase
git checkout computed-atts
make testacc
The text was updated successfully, but these errors were encountered: