Skip to content

Commit d08e08f

Browse files
Nitin Jainnitinjain999
authored andcommitted
feat: expose computed seat fields on github_copilot_organization_seat_assignment
Add created_at, pending_cancellation_date, last_activity_at, last_activity_editor, and plan_type as computed attributes sourced from GetSeatDetails. Useful for auditing seat usage.
1 parent 77f949e commit d08e08f

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

github/resource_github_copilot_organization_seat_assignment.go

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,31 @@ func resourceGithubCopilotOrganizationSeatAssignment() *schema.Resource {
2828
DiffSuppressFunc: caseInsensitive(),
2929
Description: "The login of the user to assign a Copilot seat.",
3030
},
31+
"created_at": {
32+
Type: schema.TypeString,
33+
Computed: true,
34+
Description: "Timestamp of when the seat was first assigned.",
35+
},
36+
"pending_cancellation_date": {
37+
Type: schema.TypeString,
38+
Computed: true,
39+
Description: "Date on which the seat will be cancelled, if pending cancellation.",
40+
},
41+
"last_activity_at": {
42+
Type: schema.TypeString,
43+
Computed: true,
44+
Description: "Timestamp of the user's last Copilot activity.",
45+
},
46+
"last_activity_editor": {
47+
Type: schema.TypeString,
48+
Computed: true,
49+
Description: "Editor used in the user's last Copilot activity.",
50+
},
51+
"plan_type": {
52+
Type: schema.TypeString,
53+
Computed: true,
54+
Description: "The Copilot plan type for this seat (e.g. business, enterprise).",
55+
},
3156
},
3257
}
3358
}
@@ -56,7 +81,7 @@ func resourceGithubCopilotOrganizationSeatAssignmentRead(ctx context.Context, d
5681

5782
username := d.Id()
5883

59-
_, _, err := client.Copilot.GetSeatDetails(ctx, org, username)
84+
seat, _, err := client.Copilot.GetSeatDetails(ctx, org, username)
6085
if err != nil {
6186
if ghErr, ok := errors.AsType[*github.ErrorResponse](err); ok && ghErr.Response.StatusCode == http.StatusNotFound {
6287
tflog.Info(ctx, "Copilot seat assignment no longer exists, removing from state", map[string]any{"username": username})
@@ -70,6 +95,26 @@ func resourceGithubCopilotOrganizationSeatAssignmentRead(ctx context.Context, d
7095
return diag.FromErr(err)
7196
}
7297

98+
createdAt := seat.GetCreatedAt()
99+
if err := d.Set("created_at", createdAt.String()); err != nil {
100+
return diag.FromErr(err)
101+
}
102+
if err := d.Set("pending_cancellation_date", seat.GetPendingCancellationDate()); err != nil {
103+
return diag.FromErr(err)
104+
}
105+
if err := d.Set("last_activity_editor", seat.GetLastActivityEditor()); err != nil {
106+
return diag.FromErr(err)
107+
}
108+
if err := d.Set("plan_type", seat.GetPlanType()); err != nil {
109+
return diag.FromErr(err)
110+
}
111+
112+
if lastActivity := seat.GetLastActivityAt(); !lastActivity.IsZero() {
113+
if err := d.Set("last_activity_at", lastActivity.String()); err != nil {
114+
return diag.FromErr(err)
115+
}
116+
}
117+
73118
return nil
74119
}
75120

templates/resources/copilot_organization_seat_assignment.md.tmpl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ The following arguments are supported:
2020

2121
- `username` - (Required, Forces new resource) The login of the organization member to assign a Copilot seat.
2222

23+
## Attributes Reference
24+
25+
In addition to the arguments above, the following attributes are exported:
26+
27+
- `created_at` - Timestamp of when the seat was first assigned.
28+
- `pending_cancellation_date` - Date on which the seat will be cancelled, if a cancellation is pending.
29+
- `last_activity_at` - Timestamp of the user's last Copilot activity.
30+
- `last_activity_editor` - Editor used in the user's last Copilot activity.
31+
- `plan_type` - The Copilot plan type for this seat (e.g. `business`, `enterprise`).
32+
2333
## Import
2434

2535
Copilot organization seat assignments can be imported using the username, e.g.

0 commit comments

Comments
 (0)