/
resource_import.go
37 lines (31 loc) · 1.49 KB
/
resource_import.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package tfsdk
import (
"context"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)
// 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.
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.
func ResourceImportStatePassthroughID(ctx context.Context, path *tftypes.AttributePath, req ImportResourceStateRequest, resp *ImportResourceStateResponse) {
if path == nil || tftypes.NewAttributePath().Equal(path) {
resp.Diagnostics.AddError(
"Resource Import Passthrough Missing Attribute Path",
"This is always an error in the provider. Please report the following to the provider developer:\n\n"+
"Resource ImportState method call to ResourceImportStatePassthroughID path must be set to a valid attribute path that can accept a string value.",
)
}
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path, req.ID)...)
}