@@ -21,6 +21,7 @@ import (
21
21
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
22
22
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
23
23
"github.com/hashicorp/terraform-plugin-framework/types"
24
+ "github.com/hashicorp/terraform-plugin-framework/types/basetypes"
24
25
"github.com/hashicorp/terraform-plugin-log/tflog"
25
26
)
26
27
@@ -268,7 +269,39 @@ func (r *resourceTFETeamToken) Delete(ctx context.Context, req resource.DeleteRe
268
269
}
269
270
270
271
func (r * resourceTFETeamToken ) ImportState (ctx context.Context , req resource.ImportStateRequest , resp * resource.ImportStateResponse ) {
271
- resource .ImportStatePassthroughID (ctx , path .Root ("team_id" ), req , resp )
272
+ if ! isTokenID (req .ID ) {
273
+ // Set the team ID field
274
+ resource .ImportStatePassthroughID (ctx , path .Root ("team_id" ), req , resp )
275
+ return
276
+ }
277
+
278
+ // Fetch token by ID to set attributes
279
+ token , err := r .config .Client .TeamTokens .ReadByID (ctx , req .ID )
280
+ if err != nil {
281
+ resp .Diagnostics .AddError ("Error importing team token" , err .Error ())
282
+ return
283
+ }
284
+ if token .Team == nil {
285
+ resp .Diagnostics .AddError ("Error importing team token" , "token did not return associated team" )
286
+ return
287
+ }
288
+
289
+ var expiredAt types.String
290
+ if ! token .ExpiredAt .IsZero () {
291
+ expiredAt = types .StringValue (token .ExpiredAt .Format (time .RFC3339 ))
292
+ } else {
293
+ expiredAt = types .StringNull ()
294
+ }
295
+
296
+ var description types.String
297
+ if token .Description != nil {
298
+ description = types .StringValue (* token .Description )
299
+ } else {
300
+ description = types .StringNull ()
301
+ }
302
+
303
+ result := modelFromTFEToken (types .StringValue (token .Team .ID ), types .StringValue (token .ID ), types .StringValue (token .Token ), basetypes .NewBoolNull (), expiredAt , description )
304
+ resp .Diagnostics .Append (resp .State .Set (ctx , & result )... )
272
305
}
273
306
274
307
// Determines whether the ID of the resource is the ID of the authentication token
0 commit comments