@@ -32,11 +32,16 @@ type UserDataSourceModel struct {
32
32
ID types.String `tfsdk:"id"`
33
33
Username types.String `tfsdk:"username"`
34
34
35
- Name types.String `tfsdk:"name"`
36
- Email types.String `tfsdk:"email"`
37
- Roles types.Set `tfsdk:"roles"` // owner, template-admin, user-admin, auditor (member is implicit)
38
- LoginType types.String `tfsdk:"login_type"` // none, password, github, oidc
39
- Suspended types.Bool `tfsdk:"suspended"`
35
+ Name types.String `tfsdk:"name"`
36
+ Email types.String `tfsdk:"email"`
37
+ Roles types.Set `tfsdk:"roles"` // owner, template-admin, user-admin, auditor (member is implicit)
38
+ LoginType types.String `tfsdk:"login_type"` // none, password, github, oidc
39
+ Suspended types.Bool `tfsdk:"suspended"`
40
+ AvatarURL types.String `tfsdk:"avatar_url"`
41
+ OrganizationIDs types.Set `tfsdk:"organization_ids"`
42
+ CreatedAt types.Int64 `tfsdk:"created_at"` // Unix timestamp
43
+ LastSeenAt types.Int64 `tfsdk:"last_seen_at"`
44
+ ThemePreference types.String `tfsdk:"theme_preference"`
40
45
}
41
46
42
47
func (d * UserDataSource ) Metadata (ctx context.Context , req datasource.MetadataRequest , resp * datasource.MetadataResponse ) {
@@ -57,14 +62,14 @@ func (d *UserDataSource) Schema(ctx context.Context, req datasource.SchemaReques
57
62
MarkdownDescription : "The username of the user to retrieve. This field will be populated if an ID is supplied." ,
58
63
Optional : true ,
59
64
},
60
- "email" : schema.StringAttribute {
61
- MarkdownDescription : "Email of the user." ,
62
- Computed : true ,
63
- },
64
65
"name" : schema.StringAttribute {
65
66
MarkdownDescription : "Display name of the user. Defaults to username." ,
66
67
Computed : true ,
67
68
},
69
+ "email" : schema.StringAttribute {
70
+ MarkdownDescription : "Email of the user." ,
71
+ Computed : true ,
72
+ },
68
73
"roles" : schema.SetAttribute {
69
74
MarkdownDescription : "Roles assigned to the user. Valid roles are 'owner', 'template-admin', 'user-admin', and 'auditor'." ,
70
75
Computed : true ,
@@ -78,6 +83,27 @@ func (d *UserDataSource) Schema(ctx context.Context, req datasource.SchemaReques
78
83
MarkdownDescription : "Whether the user is suspended." ,
79
84
Computed : true ,
80
85
},
86
+ "avatar_url" : schema.StringAttribute {
87
+ MarkdownDescription : "URL of the user's avatar." ,
88
+ Computed : true ,
89
+ },
90
+ "organization_ids" : schema.SetAttribute {
91
+ MarkdownDescription : "IDs of organizations the user is associated with." ,
92
+ Computed : true ,
93
+ ElementType : types .StringType ,
94
+ },
95
+ "created_at" : schema.Int64Attribute {
96
+ MarkdownDescription : "Unix timestamp of when the user was created." ,
97
+ Computed : true ,
98
+ },
99
+ "last_seen_at" : schema.Int64Attribute {
100
+ MarkdownDescription : "Unix timestamp of when the user was last seen." ,
101
+ Computed : true ,
102
+ },
103
+ "theme_preference" : schema.StringAttribute {
104
+ MarkdownDescription : "The user's preferred theme." ,
105
+ Computed : true ,
106
+ },
81
107
},
82
108
}
83
109
}
@@ -131,9 +157,9 @@ func (d *UserDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
131
157
}
132
158
133
159
data .ID = types .StringValue (user .ID .String ())
134
- data .Email = types .StringValue (user .Email )
135
160
data .Username = types .StringValue (user .Username )
136
161
data .Name = types .StringValue (user .Name )
162
+ data .Email = types .StringValue (user .Email )
137
163
roles := make ([]attr.Value , 0 , len (user .Roles ))
138
164
for _ , role := range user .Roles {
139
165
roles = append (roles , types .StringValue (role .Name ))
@@ -142,6 +168,15 @@ func (d *UserDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
142
168
data .LoginType = types .StringValue (string (user .LoginType ))
143
169
data .Suspended = types .BoolValue (user .Status == codersdk .UserStatusSuspended )
144
170
171
+ orgIDs := make ([]attr.Value , 0 , len (user .OrganizationIDs ))
172
+ for _ , orgID := range user .OrganizationIDs {
173
+ orgIDs = append (orgIDs , types .StringValue (orgID .String ()))
174
+ }
175
+ data .OrganizationIDs = types .SetValueMust (types .StringType , orgIDs )
176
+ data .CreatedAt = types .Int64Value (user .CreatedAt .Unix ())
177
+ data .LastSeenAt = types .Int64Value (user .LastSeenAt .Unix ())
178
+ data .ThemePreference = types .StringValue (user .ThemePreference )
179
+
145
180
// Save data into Terraform state
146
181
resp .Diagnostics .Append (resp .State .Set (ctx , & data )... )
147
182
}
0 commit comments