-
Notifications
You must be signed in to change notification settings - Fork 227
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
d.Set doesn't work on not computed values #951
Comments
Hi @luispresuelVenafi 👋 Thanks for raising this and sorry you ran into trouble here. Looking real quickly at that resource, it looks like its taking advantage of the Does it work if you move that logic into the I'm not sure if it was intentional that terraform-plugin-sdk/helper/schema/resource.go Lines 978 to 1002 in bb44c87
If you haven't seen already, the v2 Upgrade Guide might have some other helpful tidbits. 👍 |
Thank you for the quick response @bflad . The behavior you mention in the Read function, does work to remove the resource from state (e.g. substituting any Unfortunately, I couldn't anything related to our use case in the upgrade guide regarding Edit: I need to add, this does work during real testing using a binary. This only fails during tests scenarios |
I would certainly expect any calls to If you've already tried using I see you amended your above comment to mention this is only during acceptance testing. Can you show your testing code and the test failure output? |
Sure in the new resource_test file we'd have the following: These imports:
Then the following strings for the provider and resource
Then the following test:
And then the check function for the expiration were we gather the value from the outputs:
One thing to notice here is that before we have to cast as integer as in here: https://github.com/Venafi/terraform-provider-venafi/blob/master/venafi/resource_venafi_certificate_test.go#L1245 and now we expect an string from the This is error I get if I run the test:
Which makes sence, since the |
Ah ha -- this information is super helpful. One of the big changes from v1 to v2 was that the acceptance testing framework was changed from using (or rather, duplicating) Terraform code to handle its internals to actually calling Terraform CLI commands. It's entirely possible that certain internals of If you haven't seen, the SDK does provide some helpers that could simplify this testing code (and potentially fix it in this case), e.g. I'm wondering if swapping out the custom |
Hi @bflad, I've indeed confirmed that it was a flaw within our code since it still was using the old test driver (it seems like you mention, the internal of |
I was wondering if do you have a suggestion about using It would require to add context to the function Any suggestion to add it here, during the test function? |
If you switch To using the context-aware field In unit testing, if you don't mind the logs not showing up (until hashicorp/terraform-plugin-log#52 is resolved) you can use ctx := tflogtest.RootLogger(context.Background(), os.Stderr)
// now calls to tflog.XXX(ctx, ...) will show up in go test output with the verbose (-v) flag set |
By the way, I'm happy to keep answering questions here, but I'm going to close out the issue since there's nothing actionable (in a bug report or enhancement sense) for the maintainers. You can also submit questions to the HashiCorp Discuss Forums, where there are more folks including other provider developers who might be able to answer things as well. |
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. |
SDK version
As part migration from SDKv1 to SDKv2 we noticed of our provider that the d.Set doesn't work anymore for attributes of a resource that are not computed. When trying to "correct" the value from our provider of the
expiration_window
attribute during this section of the code our resource: https://github.com/Venafi/terraform-provider-venafi/blob/master/venafi/resource_venafi_certificate.go#L528it will no longer take effect (we want this behavior because we do a validation after our certificate resource having created that may return a new value for the expiration_window that we want to correct). Is that now intended behavior for the SDKv2? If so, what could be the better approach to reach our desired behavior for our use case. Not sure if is this a bug and there's plan to fix it in the future.
Expected Behavior
d.Set should also update the value from the resource attribute even if the resource is not computed.
Actual Behavior
d.Set doesn't update the value if the resource is not computed.
The text was updated successfully, but these errors were encountered: