Skip to content

Commit 2a9fb1b

Browse files
author
Ning Kang
committed
add import
1 parent cf51f35 commit 2a9fb1b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

internal/crud/unicorn_source.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"terraform-provider-crud/client"
77

8+
"github.com/hashicorp/terraform-plugin-framework/path"
89
"github.com/hashicorp/terraform-plugin-framework/resource"
910
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
1011
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
@@ -21,8 +22,9 @@ type unicornResourceModel struct {
2122

2223
// Ensure the implementation satisfies the expected interfaces.
2324
var (
24-
_ resource.Resource = &unicornResource{}
25-
_ resource.ResourceWithConfigure = &unicornResource{}
25+
_ resource.Resource = &unicornResource{}
26+
_ resource.ResourceWithConfigure = &unicornResource{}
27+
_ resource.ResourceWithImportState = &unicornResource{}
2628
)
2729

2830
// NewunicornResource is a helper function to simplify the provider implementation.
@@ -227,3 +229,8 @@ func (r *unicornResource) Delete(ctx context.Context, req resource.DeleteRequest
227229
return
228230
}
229231
}
232+
233+
func (r *unicornResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
234+
// Retrieve import ID and save to id attribute
235+
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
236+
}

0 commit comments

Comments
 (0)