@@ -19,12 +19,25 @@ import (
19
19
)
20
20
21
21
func diffSuppressIamUserName (_ , old , new string , d * schema.ResourceData ) bool {
22
- strippedName := strings .Split (new , "@" )[0 ]
22
+ // IAM users of type `CLOUD_IAM_USER` and `CLOUD_IAM_SERVICE_ACCOUNT` are created based on
23
+ // email addresses, but do not include the domain in the generated user. So we need
24
+ // to strip the domain in order to compare incoming values with old values.
25
+ // Group users of type `CLOUD_IAM_GROUP`, however, retain their domains as a part of their username,
26
+ // so we need to compare these directly
27
+ truncated_iam_types := []string {"CLOUD_IAM_USER" , "CLOUD_IAM_SERVICE_ACCOUNT" }
28
+ untruncated_iam_types := []string {"CLOUD_IAM_GROUP" }
23
29
24
30
userType := d .Get ("type" ).(string )
25
31
26
- if old == strippedName && strings .Contains (userType , "IAM" ) {
27
- return true
32
+ if slices .Contains (untruncated_iam_types , userType ) {
33
+ // We compare old and new directly for untruncated entries
34
+ return old == new
35
+ }
36
+
37
+ if slices .Contains (truncated_iam_types , userType ) {
38
+ // For truncated types, We strip the domain from the new value use it for comparison
39
+ strippedName := strings .Split (new , "@" )[0 ]
40
+ return old == strippedName
28
41
}
29
42
30
43
return false
@@ -351,6 +364,8 @@ func resourceSqlUserRead(d *schema.ResourceData, meta interface{}) error {
351
364
}
352
365
353
366
for _ , currentUser := range users .Items {
367
+ // `CLOUD_IAM_GROUP` users are created with the domain name in the username, unlike
368
+ // the other `CLOUD_IAM_*` user types.
354
369
if ! (strings .Contains (databaseInstance .DatabaseVersion , "POSTGRES" ) || currentUser .Type == "CLOUD_IAM_GROUP" ) {
355
370
name = strings .Split (name , "@" )[0 ]
356
371
}
0 commit comments