-
Notifications
You must be signed in to change notification settings - Fork 233
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
Returning an error still applies diff to state. #476
Comments
As per https://www.terraform.io/docs/extend/guides/v2-upgrade-guide.html#removal-of-helper-schema-resourcedata-setpartial the method has been removed and workaround implemented as shown in hashicorp/terraform-plugin-sdk#476. Signed-off-by: Stephen Hoekstra <shoekstra@schubergphilis.com>
Just to be sure I get this sentence part: Does it means that it should impact resource fields that haven't any |
hashicorp/terraform#20295 seems related to this. Still tracking down why this is happening and whether it's happening on purpose or not. There seems to be some ambiguity in the Terraform Resource Instance Change Lifecycle doc as to whether the constraints on what state can be returned from
I don't see how that could yield a correct state in the face of an error. Research is still ongoing though. |
Sorry, @treywelsh, this one's on me. I meant
Number 2 holds up if and only if users aren't running with the |
Just to add an obvious use case to the That particular value cannot be refreshed in the So, without particular handling, we can end up with a wrong password in the statefile compared to the actual resource and it can lead to serious problems. |
That after a failed update changes to the resource are still applied is a know bug (hashicorp/terraform-plugin-sdk#476). It affects attributes that are not retrieved via the Get function and set only by the provider. custom_404_file_path is such a field. As workaround d.Partial() can be called. This is more simple then the revertUpdateValues() implementation.
That after a failed update changes to the resource are still applied is a know bug (hashicorp/terraform-plugin-sdk#476). It affects attributes that are not retrieved via the Get function and set only by the provider. custom_404_file_path is such a field. As workaround d.Partial() can be called. This is more simple then the revertUpdateValues() implementation.
We've hit this issue in NSXT provider in several scenarios:
Seems like can only use the workaround suggested above Additional question - we don't see this behavior happening for all resources, some maintain correct state after seemingly same kind of error. It would help us a lot to get some understanding what could cause this difference. Thanks in advance! |
SDK version
present in v1.13.1, not tested in previous versions, still need to determine when the bug was introduced, or if it was intended behavior that wasn't communicated clearly
Relevant provider source code
Terraform Configuration Files
For create:
For update:
Debug Output
To be added.
Expected Behavior
On update, because an error is returned, the diff should not be applied to state, so
foo
should still be123
, as the error indicates that the diff was not used.Actual Behavior
On update,
foo
is set to456
in state, even though the error was correctly returned, indicating that the diff was applied anyways.Steps to Reproduce
terraform apply
foo
to456
in config fileterraform apply
terraform show foo_resource.testing.foo
Workarounds
Modifying your code to this correctly discards the diff in the case of error, not applying it to state.
Impact
Most providers shouldn't notice this. The apply will be ended when the error is encountered, so no downstream resources are interpolating incorrect results on the run that errored. And before the next apply,
refresh
should run, updating the information in state to match reality. This should therefore only impact resources that don't or can't update all their fields inGet
, or users that run with-refresh=false
, which is discouraged.The text was updated successfully, but these errors were encountered: