@@ -50,7 +50,7 @@ func ResourceUser() *schema.Resource {
5050 "username" : {
5151 Type : schema .TypeString ,
5252 Optional : true ,
53- Computed : true , // For Guest users, it is equal to the email
53+ Computed : true ,
5454 Description : "The member's username" ,
5555 },
5656 "password" : {
@@ -76,7 +76,7 @@ func ResourceUser() *schema.Resource {
7676 "locale" : {
7777 Type : schema .TypeString ,
7878 Optional : true ,
79- Computed : true , // It gets automatically set by the API
79+ Computed : true ,
8080 Description : "The member's locale" ,
8181 },
8282 // Computed data
@@ -141,16 +141,10 @@ func createUserRequestBody(d *schema.ResourceData, isMember bool) *iam.CreateUse
141141 SendWelcomeEmail : d .Get ("send_welcome_email" ).(bool ),
142142 Username : d .Get ("username" ).(string ),
143143 Password : d .Get ("password" ).(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 ),
144+ FirstName : d .Get ("first_name" ).(string ),
145+ LastName : d .Get ("last_name" ).(string ),
146+ PhoneNumber : d .Get ("phone_number" ).(string ),
147+ Locale : d .Get ("locale" ).(string ),
154148 },
155149 }
156150 } else {
@@ -236,28 +230,33 @@ func resourceIamUserUpdate(ctx context.Context, d *schema.ResourceData, m interf
236230 return diag .FromErr (err )
237231 }
238232
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- */
251- if d .HasChanges ("tags" ) {
252- _ , err = api .UpdateUser (& iam.UpdateUserRequest {
253- UserID : user .ID ,
254- Tags : types .ExpandUpdatedStringsPtr (d .Get ("tags" )),
255- }, scw .WithContext (ctx ))
256- if err != nil {
257- return diag .FromErr (err )
233+ if user .Type == "Guest" {
234+ // Users of type 'Guest' only support the update of tags.
235+ if d .HasChanges ("tags" ) {
236+ _ , err = api .UpdateUser (& iam.UpdateUserRequest {
237+ UserID : user .ID ,
238+ Tags : types .ExpandUpdatedStringsPtr (d .Get ("tags" )),
239+ }, scw .WithContext (ctx ))
240+ if err != nil {
241+ return diag .FromErr (err )
242+ }
243+ }
244+ } else {
245+ if d .HasChanges ("tags" , "email" , "first_name" , "last_name" , "phone_number" , "locale" ) {
246+ _ , err = api .UpdateUser (& iam.UpdateUserRequest {
247+ UserID : user .ID ,
248+ Tags : types .ExpandUpdatedStringsPtr (d .Get ("tags" )),
249+ Email : scw .StringPtr (d .Get ("email" ).(string )),
250+ FirstName : scw .StringPtr (d .Get ("first_name" ).(string )),
251+ LastName : scw .StringPtr (d .Get ("last_name" ).(string )),
252+ PhoneNumber : scw .StringPtr (d .Get ("phone_number" ).(string )),
253+ Locale : scw .StringPtr (d .Get ("locale" ).(string )),
254+ }, scw .WithContext (ctx ))
255+ if err != nil {
256+ return diag .FromErr (err )
257+ }
258258 }
259259 }
260-
261260 return resourceIamUserRead (ctx , d , m )
262261}
263262
0 commit comments