Skip to content

Commit 2cdae5d

Browse files
giacomosirriGnoale
authored andcommitted
Add comments
1 parent caa4de6 commit 2cdae5d

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

internal/services/iam/user.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ func ResourceUser() *schema.Resource {
131131

132132
func createUserRequestBody(d *schema.ResourceData, isMember bool) *iam.CreateUserRequest {
133133
if isMember {
134+
// Create and return a Member user.
134135
return &iam.CreateUserRequest{
135136
OrganizationID: d.Get("organization_id").(string),
136137
Tags: types.ExpandStrings(d.Get("tags")),
@@ -140,13 +141,20 @@ func createUserRequestBody(d *schema.ResourceData, isMember bool) *iam.CreateUse
140141
SendWelcomeEmail: d.Get("send_welcome_email").(bool),
141142
Username: d.Get("username").(string),
142143
Password: d.Get("password").(string),
143-
FirstName: d.Get("first_name").(string),
144-
LastName: d.Get("last_name").(string),
145-
PhoneNumber: d.Get("phone_number").(string),
146-
Locale: d.Get("locale").(string),
144+
/* N.B.: As of April 2025, these last four parameters are ignored by the API,
145+
* meaning that even if you set them when creating the user, the resulting user
146+
* will have empty strings as values for these fields (with the exception of
147+
* 'locale' for Member users, which is always set to 'en_US'). Trying to update
148+
* these fields is also useless, as the API ignores changes as well.
149+
*/
150+
FirstName: d.Get("first_name").(string),
151+
LastName: d.Get("last_name").(string),
152+
PhoneNumber: d.Get("phone_number").(string),
153+
Locale: d.Get("locale").(string),
147154
},
148155
}
149156
} else {
157+
// Create and return a Guest user.
150158
return &iam.CreateUserRequest{
151159
OrganizationID: d.Get("organization_id").(string),
152160
Email: scw.StringPtr(d.Get("email").(string)),
@@ -228,6 +236,18 @@ func resourceIamUserUpdate(ctx context.Context, d *schema.ResourceData, m interf
228236
return diag.FromErr(err)
229237
}
230238

239+
/*
240+
* The API endpoint for updating a user allows changes to the 'tags' and 'email' fields
241+
* for both the Guest and Member user types, plus changes to 'first_name', 'last_name',
242+
* 'phone_number', and 'locale' when the user is of type Member.
243+
* However, for some reason the API ignores all changes to the Member-specific fields
244+
* when updating. This leaves only 'email' and 'tags' as fields that potentially support
245+
* changes.
246+
* The field 'email' is designed as 'ForceNew' for this resource, which means that a
247+
* change in its value requires the replacement (destroy and create) of the managed
248+
* resource instance.
249+
* All in all, as of April 2025, the only field that actually supports changes is 'tags'.
250+
*/
231251
if d.HasChanges("tags") {
232252
_, err = api.UpdateUser(&iam.UpdateUserRequest{
233253
UserID: user.ID,

0 commit comments

Comments
 (0)