5
5
"fmt"
6
6
"time"
7
7
8
+ "github.com/hashicorp/terraform-plugin-framework/path"
8
9
"github.com/hashicorp/terraform-plugin-framework/resource"
9
10
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
10
11
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
@@ -15,8 +16,9 @@ import (
15
16
16
17
// Ensure the implementation satisfies the expected interfaces.
17
18
var (
18
- _ resource.Resource = & ClusterRegistrationResource {}
19
- _ resource.ResourceWithConfigure = & ClusterRegistrationResource {}
19
+ _ resource.Resource = & ClusterRegistrationResource {}
20
+ _ resource.ResourceWithConfigure = & ClusterRegistrationResource {}
21
+ _ resource.ResourceWithImportState = & ClusterRegistrationResource {}
20
22
)
21
23
22
24
// NewClusterRegistrationResource returns a new resource.Resource.
@@ -47,6 +49,7 @@ func (r *ClusterRegistrationResource) Metadata(_ context.Context, req resource.M
47
49
// Schema returns the resource schema.
48
50
func (r * ClusterRegistrationResource ) Schema (_ context.Context , _ resource.SchemaRequest , resp * resource.SchemaResponse ) {
49
51
resp .Schema = schema.Schema {
52
+ Description : "Manage cluster registration" ,
50
53
Attributes : map [string ]schema.Attribute {
51
54
"cluster_name" : schema.StringAttribute {
52
55
Required : true ,
@@ -60,7 +63,7 @@ func (r *ClusterRegistrationResource) Schema(_ context.Context, _ resource.Schem
60
63
Description : "Human-readable display name" ,
61
64
},
62
65
"credentials" : schema.StringAttribute {
63
- Required : true ,
66
+ Optional : true ,
64
67
Sensitive : true ,
65
68
Description : "Path to kubeconfig file" ,
66
69
PlanModifiers : []planmodifier.String {
@@ -143,6 +146,7 @@ func (c *ClusterRegistrationResource) Read(ctx context.Context, req resource.Rea
143
146
144
147
// Overwrite items with refreshed state
145
148
state .ClusterName = remoteState .ClusterName
149
+ state .DisplayName = remoteState .DisplayName
146
150
state .Description = remoteState .Description
147
151
state .Id = remoteState .Id
148
152
@@ -214,6 +218,12 @@ func (c *ClusterRegistrationResource) Delete(ctx context.Context, req resource.D
214
218
}
215
219
}
216
220
221
+ // ImportState imports the resource.
222
+ func (c * ClusterRegistrationResource ) ImportState (ctx context.Context , req resource.ImportStateRequest , resp * resource.ImportStateResponse ) {
223
+ // Terraform will automatically call the resource's Read method to import the rest of the Terraform state
224
+ resource .ImportStatePassthroughID (ctx , path .Root ("cluster_name" ), req , resp )
225
+ }
226
+
217
227
// Configure configures the resource.
218
228
func (c * ClusterRegistrationResource ) Configure (ctx context.Context , req resource.ConfigureRequest , resp * resource.ConfigureResponse ) {
219
229
if req .ProviderData == nil {
0 commit comments