hashicorp / terraform-plugin-sdk

Terraform Plugin SDK enables building plugins (providers) to manage any service providers or custom in-house solutions
https://developer.hashicorp.com/terraform/plugin
Mozilla Public License 2.0
439 stars 232 forks source link

Diagnostics Handling with helper/schema.ResourceImporter #523

Open bflad opened 4 years ago

bflad commented 4 years ago

SDK version

v2.0.0

Use-cases

Version 2 of the Terraform Plugin SDK added some awesome diagnostics handling to many of the core provider resource handling functions. It appears that resource import handling didn't receive the same love however.

https://github.com/hashicorp/terraform-plugin-sdk/blob/b8c88233915352e876c277b19992dc3ebfea7d94/helper/schema/resource_importer.go#L50

It would be great if resource import functions could implement warnings in addition to errors. For example, a provider today cannot signal a deprecation of import syntax or provide other informational messages to the Terraform user interface.

Attempted Solutions

Proposal

Support the return type of diag.Diagnostic from a schema.ResourceImporter function field. When presented with:

References

bflad commented 2 years ago

Bummer, in investigating https://github.com/hashicorp/terraform-plugin-sdk/issues/877, it appears that helper/schema.Provider.ImportState is unfortunately an exported method signature, therefore it is protected by major version compatibility guarantees. Creating a separate method, that then calls a new diagnostics compatible field on ResourceImporter, would introduce its own oddities and could be confusing for anyone building on this API, so therefore wouldn't likely be a good path forward here here either.

Rather than keeping this open, I think the best recommendation then is convert resources over to terraform-plugin-framework, which properly allows diagnostics during resource import logic. Very soon we will support muxing terraform-plugin-sdk/v2 and terraform-plugin-framework providers together without requiring Terraform CLI 1.0 or later, so there will be a migration path to getting this functionality without introducing breaking changes.

github-actions[bot] commented 2 years ago

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. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.