Skip to content

Commit

Permalink
tfsdk: Remove ResourceImportStateNotImplemented() function (#312)
Browse files Browse the repository at this point in the history
Reference: #297
  • Loading branch information
bflad committed May 3, 2022
1 parent 09acc68 commit 72e4d38
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 44 deletions.
3 changes: 3 additions & 0 deletions .changelog/312.txt
@@ -0,0 +1,3 @@
```release-note:breaking-change
tfsdk: The `ResourceImportStateNotImplemented()` function has been removed. Remove the `Resource` type `ImportState` method instead for resources that should not support import.
```
2 changes: 1 addition & 1 deletion internal/proto6server/serve_import.go
Expand Up @@ -135,7 +135,7 @@ func (s *Server) importResourceState(ctx context.Context, req *tfprotov6.ImportR
resp.Diagnostics.AddError(
"Missing Resource Import State",
"An unexpected error was encountered when importing the resource. This is always a problem with the provider. Please give the following information to the provider developer:\n\n"+
"Resource ImportState method returned no State in response. If import is intentionally not supported, call the ResourceImportStateNotImplemented() function or return an error.",
"Resource ImportState method returned no State in response. If import is intentionally not supported, remove the Resource type ImportState method or return an error.",
)
return
}
Expand Down
23 changes: 1 addition & 22 deletions internal/proto6server/serve_import_test.go
Expand Up @@ -96,27 +96,6 @@ func TestServerImportResourceState(t *testing.T) {
},
},
},
"ResourceImportStateNotImplemented": {
req: &tfprotov6.ImportResourceStateRequest{
ID: "test",
TypeName: "test_import_state",
},

impl: func(ctx context.Context, req tfsdk.ImportResourceStateRequest, resp *tfsdk.ImportResourceStateResponse) {
//nolint:staticcheck // This will be removed before the next minor release.
tfsdk.ResourceImportStateNotImplemented(ctx, "", resp)
},

resp: &tfprotov6.ImportResourceStateResponse{
Diagnostics: []*tfprotov6.Diagnostic{
{
Summary: "Resource Import Not Implemented",
Severity: tfprotov6.DiagnosticSeverityError,
Detail: "This resource does not support import. Please contact the provider developer for additional information.",
},
},
},
},
"imported_resource_conversion_error": {
req: &tfprotov6.ImportResourceStateRequest{
ID: "test",
Expand Down Expand Up @@ -153,7 +132,7 @@ func TestServerImportResourceState(t *testing.T) {
Summary: "Missing Resource Import State",
Severity: tfprotov6.DiagnosticSeverityError,
Detail: "An unexpected error was encountered when importing the resource. This is always a problem with the provider. Please give the following information to the provider developer:\n\n" +
"Resource ImportState method returned no State in response. If import is intentionally not supported, call the ResourceImportStateNotImplemented() function or return an error.",
"Resource ImportState method returned no State in response. If import is intentionally not supported, remove the Resource type ImportState method or return an error.",
},
},
},
Expand Down
Expand Up @@ -86,7 +86,3 @@ func (r testServeResourceUpgradeStateNotImplemented) Update(ctx context.Context,
func (r testServeResourceUpgradeStateNotImplemented) Delete(ctx context.Context, req tfsdk.DeleteResourceRequest, resp *tfsdk.DeleteResourceResponse) {
// Intentionally blank. Not expected to be called during testing.
}
func (r testServeResourceUpgradeStateNotImplemented) ImportState(ctx context.Context, req tfsdk.ImportResourceStateRequest, resp *tfsdk.ImportResourceStateResponse) {
//nolint:staticcheck // This will be removed before the next minor release.
tfsdk.ResourceImportStateNotImplemented(ctx, "intentionally not implemented", resp)
}
17 changes: 0 additions & 17 deletions tfsdk/resource_import.go
Expand Up @@ -20,23 +20,6 @@ type ResourceWithImportState interface {
ImportState(context.Context, ImportResourceStateRequest, *ImportResourceStateResponse)
}

// ResourceImportStateNotImplemented is a helper function to return an error
// diagnostic about the resource not supporting import. The details defaults
// to a generic message to contact the provider developer, but can be
// customized to provide specific information or recommendations.
//
// Deprecated: Remove the ImportState method from the Resource instead.
func ResourceImportStateNotImplemented(ctx context.Context, details string, resp *ImportResourceStateResponse) {
if details == "" {
details = "This resource does not support import. Please contact the provider developer for additional information."
}

resp.Diagnostics.AddError(
"Resource Import Not Implemented",
details,
)
}

// ResourceImportStatePassthroughID is a helper function to set the import
// identifier to a given state attribute path. The attribute must accept a
// string value.
Expand Down

0 comments on commit 72e4d38

Please sign in to comment.