-
Notifications
You must be signed in to change notification settings - Fork 286
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
upgrade provider to use terraform-plugin-sdk v2 #492
upgrade provider to use terraform-plugin-sdk v2 #492
Conversation
Thanks for taking this on @tdyas! I haven't done a deep review yet, but I wanted to flag that the acceptance tests currently all fail with:
Looks like One other thing we need to consider is that providers built with v2 of the SDK are incompatible with Terraform 0.11 cli. As a result, HashiCorp recommends the provider make a major release when doing this upgrade.
|
Pushed a change to add I was able to run |
So one thing I'm seeing is that we have a lot of tests that need to use a client directly to access the API and verify the existence of a resource. They use a pattern like:
These are all panicking with:
Also, not entirely sure what happened, but there seems to be a lot of noise in the diff for the vendor directory. GitHub |
The AWS provider has been ported to the v2 SDK. We probably should use a similar pattern to how they consistently initialize the provider and the ProviderFactories to the same instance: https://github.com/terraform-providers/terraform-provider-aws/blob/8756a697db23a964e4af16b950af94e7c26885ab/aws/provider_test.go#L34-L59 |
e54089f
to
bd66b5c
Compare
Rebased and squashed the commits. Found a straggler reference to the v1 SDK in the sort support in datalist package. Also fixed the provider setup in tests to set |
This is fine in master, but causes a failure on all project related tests in this branch:
|
Another panic that passes on master:
Looks like this is a real bug that should be fixed either way: |
The panics are occurring in tests now now because the v2 SDK changes the So clearly uncovering bugs as the change was made to do! |
@tdyas Definitely! After working through those, I'm running into a number of failures to datasource tests that pass on master where the problem is not immediately clear to me. For example https://gist.github.com/andrewsomething/84fa93f00dbaebaf4ea1d5b974206693 |
I've seen this issue when I was writing tests for some prior contributions. I had to first create the resource in a separate test step (without any checks) and then do a second test step with that resource still there and the added data source: terraform-provider-digitalocean/digitalocean/datasource_digitalocean_projects_test.go Lines 65 to 67 in c932c35
|
I fixed the tests for |
Co-authored-by: Andrew Starr-Bochicchio <andrewsomething@users.noreply.github.com>
Co-authored-by: Andrew Starr-Bochicchio <andrewsomething@users.noreply.github.com>
Co-authored-by: Andrew Starr-Bochicchio <andrewsomething@users.noreply.github.com>
Co-authored-by: Andrew Starr-Bochicchio <andrewsomething@users.noreply.github.com>
Probably worth vendoring those set helpers and then switching to the SDK version once that PR actually lands and is released. |
f3d4cc1
to
6963b94
Compare
@andrewsomething: I brought the PR branch up to your latest commit on the other branch. I also vendored the TypeSet helpers as |
…igitalocean/terraform-provider-digitalocean into upgrade_terraform_plugin_sdk_to_v2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thanks for all your work on this @tdyas!
This PR upgrades the provider to use v2 of the terraform-plugin-sdk.
This makes the minimum necessary changes to get the provider to work:
The
hashcode.String
function was made internal to the SDK. The implementation was copied to a new function:SDKHashString
terraform.ResourceProvider
was removed. Code now uses*schema.Provider
directly.schema.CustomizeDiffFunc
now takes context.Context parameter.The
SetPartial
function was removed. I left in the calls to d.Partial but the partial state usage need to be audited for correctness.The
Removed
attribute for obsolete fields was itself removed. I removed the instance of it in the provider.Why upgrade to v2? It provides the opportunity to update resources/datasources to get passed context.Context parameters plus provider better diagnostics in error cases among other new features.
@andrewsomething: Could you submit this for a full run of the acceptance tests?