-
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
Computed attrs are not set to unknown after a AttributePlanModifier causes a non-empty plan #456
Comments
Hi @goncalo-rodrigues 👋 Thank you for raising this and sorry this caused you some trouble. The behavior you mention is an artifact of the existing internal implementation of resource planning in the framework, where the following steps are executed if the resource is not planned for destruction:
Since you have an attribute plan modifier which always marks the planned attribute value as changed to a new value and since schema-based plan modification happens after the unknown marking, its expected other Computed attributes would be missing the unknown handling, given the current framework implementation. There have been some debates whether the schema-based plan modifiers and resource-level plan modification should also run before the unknown marking, but the use cases that might require that behavior have not been clear, so it has been left in its current state for awhile now. This is where it would be great to understand your use case a little more and expected behavior of Terraform/the provider in this case. Are you wanting every Terraform execution to show a planned/drift difference? If not, you should be able to protect the attribute plan modifier from changing the value every execution with The details are a little hazy at the moment (I apologize) but I thought Terraform would only check a resource plan if a resource had a configuration change. If that's not the case, then I'm guessing Terraform would check a no-configuration-change resource plan to support how the prior provider development SDK was implemented so diagnostics could be raised in certain validation scenarios as those prior validators did not have access to the entire configuration. As mentioned above, the framework does not protect schema-based plan modification or resource-level plan modification from a no-operation plan currently. The schema-based validation in this framework might have potentially offset the need for this, so we could potentially change this behavior. There may be use cases that I'm forgetting though, so I would be hesitant to rush to change this framework planning behavior. Hope this makes sense and thanks again for raising this. |
Just to cross-reference an existing issue for this: #183 |
Then it makes perfect sense on why it is happening. I don't want to do this logic What I'm trying to implement is something like drift detection for attributes outside what's declared in Terraform schema. For example, let's say a VM has a status that can be one of [crashed, running]. By default, the status is running and this cannot be set by the user. If the VM ends up being in the "crashed" status, I want to notify the user when they try to do My specific use case is a bit more nuanced. We have a bunch of attributes that we don't track (in aws, azure and gcp resources) but they have to be set in a certain way. If they get changed by whatever reason then we have an attribute that tracks this drift called "resource_status". Resource status is null if everything is as expected, but if there's any drift then it gets changed to "needs_update". |
Hi! I have a similar situation to @goncalo-rodrigues :
The issue I am facing: if the
This appears to be related to using a planmodifier to set a default value on the If i understand what has been discussed already, the reason this error occurs, is because:
Is that correct? afaik, the workaround Is there something else that I could try? thanks! 🙂 |
for my usecase, i was able to workaround this to some extent by implementing the but it seems pretty cumbersome.... is there a better way?
|
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. 👍 @MrFishFinger you may also be looking for something like #605 if the default value handling does not cover your use case completely |
thanks @bflad , the switch to more concretely, i removed our custom PlanModifier, and replaced it with See below for detail:
|
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
v0.11.1
Relevant provider source code
Resource has a computed field (e.g. timestamp) that might be changed upon any update. Terraform normally sets it to unknown on any plan (correctly) if there's anything to update.
However, if the plan is changed from an empty plan to a required update due to an AttributePlanModifier, it is no longer set to unknown.
Inconsistent planning
If update is triggered by a user change to a config, we get this plan:
If instead the user changed nothing, but a plan is still created due to the AttributePlanModifier, we get:
which generates the error after the apply is successful:
╷
│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to test.test, provider "provider["hashicorp.com/dev/multy"]" produced an unexpected new value: timestamp: was cty.StringVal("2022-08-19T10:29:57+00:00"), but now cty.StringVal("2022-08-19T10:33:51+00:00").
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
So, my question is: why does this differ in these 2 cases? Is this a known bug? Is there a workaround?
The text was updated successfully, but these errors were encountered: