generated from hashicorp/terraform-provider-scaffolding
/
resource_user.go
1826 lines (1654 loc) · 59.1 KB
/
resource_user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package googleworkspace
import (
"context"
"encoding/json"
"fmt"
"log"
"net/mail"
"reflect"
"strconv"
"time"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
directory "google.golang.org/api/admin/directory/v1"
"google.golang.org/api/googleapi"
)
func diffSuppressEmails(k, old, new string, d *schema.ResourceData) bool {
stateEmails, configEmails := d.GetChange("emails")
// User aliases and other alternate emails (added by Google and denoted by no `type`),
// are auto-added to the email list, even if it's not configured that way.
// Only show a diff if the other emails differ.
subsetEmails := []interface{}{}
aliases := listOfInterfacestoStrings(d.Get("aliases").([]interface{}))
for _, se := range stateEmails.([]interface{}) {
email := se.(map[string]interface{})
emailAddress := email["address"].(string)
emailType := email["type"].(string)
if emailType == "" || stringInSlice(aliases, emailAddress) {
continue
}
subsetEmails = append(subsetEmails, se)
}
return reflect.DeepEqual(subsetEmails, configEmails.([]interface{}))
}
func diffSuppressCustomSchemas(_, _, _ string, d *schema.ResourceData) bool {
old, new := d.GetChange("custom_schemas")
customSchemasOld := old.([]interface{})
customSchemasNew := new.([]interface{})
// transform the blocks
//
// custom_schemas {
// schema_name = "a"
//
// schema_values = {
// "bar" = jsonencode("Bar")
// }
// }
//
// custom_schemas {
// schema_name = "b"
//
// schema_values = {
// "baz" = jsonencode("Baz")
// }
// }
//
// into a 2 dimentional map[string]map[string]string
//
// {
// "a": {
// "bar": "Bar",
// },
// "b": {
// "baz": "Baz",
// },
// }
//
// and use reflect.DeepEqual to compare
oldMap := transformCustomSchemasTo2DMap(customSchemasOld)
newMap := transformCustomSchemasTo2DMap(customSchemasNew)
return reflect.DeepEqual(oldMap, newMap)
}
func transformCustomSchemasTo2DMap(customSchemas []interface{}) map[string]map[string]string {
result := make(map[string]map[string]string)
for _, schema := range customSchemas {
s := schema.(map[string]interface{})
schemaValues := make(map[string]string)
for k, v := range s["schema_values"].(map[string]interface{}) {
// ensure if field is list that it is sorted for comparison
// google stores unordered multi-value fields
var list []interface{}
if err := json.Unmarshal([]byte(v.(string)), &list); err == nil {
sorted := sortListOfInterfaces(list)
encoded, err := json.Marshal(sorted)
if err != nil {
panic(err)
}
schemaValues[k] = string(encoded)
} else {
schemaValues[k] = v.(string)
}
}
result[s["schema_name"].(string)] = schemaValues
}
return result
}
func resourceUser() *schema.Resource {
return &schema.Resource{
// This description is used by the documentation generator and the language server.
Description: "User resource manages Google Workspace Users. User resides " +
"under the `https://www.googleapis.com/auth/admin.directory.user` client scope.",
CreateContext: resourceUserCreate,
ReadContext: resourceUserRead,
UpdateContext: resourceUserUpdate,
DeleteContext: resourceUserDelete,
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(5 * time.Minute),
Update: schema.DefaultTimeout(5 * time.Minute),
},
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Schema: map[string]*schema.Schema{
"id": {
Description: "The unique ID for the user.",
Type: schema.TypeString,
Computed: true,
},
"primary_email": {
Description: "The user's primary email address. The primaryEmail must be unique and cannot be an alias " +
"of another user.",
Type: schema.TypeString,
Required: true,
},
"password": {
Description: "Stores the password for the user account. A password can contain any combination of " +
"ASCII characters. A minimum of 8 characters is required. The maximum length is 100 characters. " +
"As the API does not return the value of password, this field is write-only, and the value stored " +
"in the state will be what is provided in the configuration. The field is required on create and will " +
"be empty on import.",
Type: schema.TypeString,
Optional: true,
Sensitive: true,
ValidateDiagFunc: validation.ToDiagFunc(validation.StringLenBetween(8, 100)),
},
"hash_function": {
Description: "Stores the hash format of the password property. We recommend sending the password " +
"property value as a base 16 bit hexadecimal-encoded hash value. Set the hashFunction values " +
"as either the SHA-1, MD5, or crypt hash format.",
Type: schema.TypeString,
Optional: true,
},
"is_admin": {
Description: "Indicates a user with super admininistrator privileges.",
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"is_delegated_admin": {
Description: "Indicates if the user is a delegated administrator.",
Type: schema.TypeBool,
Computed: true,
},
"agreed_to_terms": {
Description: "This property is true if the user has completed an initial login and accepted the " +
"Terms of Service agreement.",
Type: schema.TypeBool,
Computed: true,
},
"suspended": {
Description: "Indicates if user is suspended.",
Type: schema.TypeBool,
Optional: true,
},
"change_password_at_next_login": {
Description: "Indicates if the user is forced to change their password at next login. This setting " +
"doesn't apply when the user signs in via a third-party identity provider.",
Type: schema.TypeBool,
Optional: true,
},
"ip_allowlist": {
Description: "If true, the user's IP address is added to the allow list.",
Type: schema.TypeBool,
Optional: true,
},
// TODO: (mbang) Add ValidateDiagFunc for max size when it's allowed on lists
// (https://github.com/hashicorp/terraform-plugin-sdk/issues/156)
"name": {
Description: "Holds the given and family names of the user, and the read-only fullName value. " +
"The maximum number of characters in the givenName and in the familyName values is 60. " +
"In addition, name values support unicode/UTF-8 characters, and can contain spaces, letters (a-z), " +
"numbers (0-9), dashes (-), forward slashes (/), and periods (.). " +
"Maximum allowed data size for this field is 1Kb.",
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"full_name": {
Description: "The user's full name formed by concatenating the first and last name values.",
Type: schema.TypeString,
Computed: true,
},
"family_name": {
Description: "The user's last name.",
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validation.ToDiagFunc(validation.StringLenBetween(1, 60)),
},
"given_name": {
Description: "The user's first name.",
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: validation.ToDiagFunc(validation.StringLenBetween(1, 60)),
},
},
},
},
"etag": {
Description: "ETag of the resource.",
Type: schema.TypeString,
Computed: true,
},
// TODO: (mbang) Add ValidateDiagFunc for max size when it's allowed on lists
// (https://github.com/hashicorp/terraform-plugin-sdk/issues/156)
"emails": {
Description: "A list of the user's email addresses. The maximum allowed data size is 10Kb.",
Type: schema.TypeList,
Optional: true,
Computed: true,
DiffSuppressFunc: diffSuppressEmails,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"address": {
Description: "The user's email address. Also serves as the email ID. " +
"This value can be the user's primary email address or an alias.",
Type: schema.TypeString,
Optional: true,
},
"custom_type": {
Description: "If the value of type is custom, this property contains " +
"the custom type string.",
Type: schema.TypeString,
Optional: true,
},
"primary": {
Description: "Indicates if this is the user's primary email. " +
"Only one entry can be marked as primary.",
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"type": {
Description: "The type of the email account. " +
"Acceptable values: `custom`, `home`, `other`, `work`.",
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validation.ToDiagFunc(
validation.StringInSlice([]string{"custom", "home", "other", "work"}, false),
),
},
},
},
},
// TODO: (mbang) Add ValidateDiagFunc for max size when it's allowed on lists
// (https://github.com/hashicorp/terraform-plugin-sdk/issues/156)
"external_ids": {
Description: "A list of external IDs for the user, such as an employee or network ID. " +
"The maximum allowed data size is 2Kb.",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"custom_type": {
Description: "If the external ID type is custom, this property contains the custom value and " +
"must be set.",
Type: schema.TypeString,
Optional: true,
},
"type": {
Description: "The type of external ID. If set to custom, customType must also be set. " +
"Acceptable values: `account`, `custom`, `customer`, `login_id`, `network`, `organization`.",
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validation.ToDiagFunc(
validation.StringInSlice([]string{"account", "custom", "customer", "login_id",
"network", "organization"}, false),
),
},
"value": {
Description: "The value of the ID.",
Type: schema.TypeString,
Required: true,
},
},
},
},
// TODO: (mbang) Add ValidateDiagFunc for max size when it's allowed on lists
// (https://github.com/hashicorp/terraform-plugin-sdk/issues/156)
"relations": {
Description: "A list of the user's relationships to other users. " +
"The maximum allowed data size for this field is 2Kb.",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"custom_type": {
Description: "If the value of type is custom, this property contains " +
"the custom type string.",
Type: schema.TypeString,
Optional: true,
},
"type": {
Description: "The type of relation. " +
"Acceptable values: `admin_assistant`, `assistant`, `brother`, `child`, `custom`, " +
"`domestic_partner`, `dotted_line_manager`, `exec_assistant`, `father`, `friend`, " +
"`manager`, `mother`, `parent`, `partner`, `referred_by`, `relative`, `sister`, " +
"`spouse`.",
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validation.ToDiagFunc(
validation.StringInSlice([]string{"admin_assistant", "assistant", "brother", "child",
"custom", "domestic_partner", "dotted_line_manager", "exec_assistant", "father",
"friend", "manager", "mother", "parent", "partner", "referred_by", "relative",
"sister"}, false),
),
},
"value": {
Description: "The name of the person the user is related to.",
Type: schema.TypeString,
Required: true,
},
},
},
},
"aliases": {
Description: "asps.list of the user's alias email addresses.",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"is_mailbox_setup": {
Description: "Indicates if the user's Google mailbox is created. This property is only applicable " +
"if the user has been assigned a Gmail license.",
Type: schema.TypeBool,
Computed: true,
},
"customer_id": {
Description: "The customer ID to retrieve all account users. You can use the alias my_customer to " +
"represent your account's customerId. As a reseller administrator, you can use the resold " +
"customer account's customerId. To get a customerId, use the account's primary domain in the " +
"domain parameter of a users.list request.",
Type: schema.TypeString,
Computed: true,
},
// TODO: (mbang) AtLeastOneOf (https://github.com/hashicorp/terraform-plugin-sdk/issues/470)
// And add ValidateDiagFunc for max size when it's allowed on lists
// (https://github.com/hashicorp/terraform-plugin-sdk/issues/156)
"addresses": {
Description: "A list of the user's addresses. The maximum allowed data size is 10Kb.",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"country": {
Description: "Country",
Type: schema.TypeString,
Optional: true,
},
"country_code": {
Description: "The country code. Uses the ISO 3166-1 standard.",
Type: schema.TypeString,
Optional: true,
},
"custom_type": {
Description: "If the address type is custom, this property contains the custom value.",
Type: schema.TypeString,
Optional: true,
},
"extended_address": {
Description: "For extended addresses, such as an address that includes a sub-region.",
Type: schema.TypeString,
Optional: true,
},
"formatted": {
Description: "A full and unstructured postal address. This is not synced with the " +
"structured address fields.",
Type: schema.TypeString,
Optional: true,
},
"locality": {
Description: "The town or city of the address.",
Type: schema.TypeString,
Optional: true,
},
"po_box": {
Description: "The post office box, if present.",
Type: schema.TypeString,
Optional: true,
},
"postal_code": {
Description: "The ZIP or postal code, if applicable.",
Type: schema.TypeString,
Optional: true,
},
"primary": {
Description: "If this is the user's primary address. The addresses list may contain " +
"only one primary address.",
Type: schema.TypeBool,
Optional: true,
},
"region": {
Description: "The abbreviated province or state.",
Type: schema.TypeString,
Optional: true,
},
"source_is_structured": {
Description: "Indicates if the user-supplied address was formatted. " +
"Formatted addresses are not currently supported.",
Type: schema.TypeBool,
Optional: true,
},
"street_address": {
Description: "The street address, such as 1600 Amphitheatre Parkway. " +
"Whitespace within the string is ignored; however, newlines are significant.",
Type: schema.TypeString,
Optional: true,
},
"type": {
Description: "The address type. " +
"Acceptable values: `custom`, `home`, `other`, `work`.",
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validation.ToDiagFunc(
validation.StringInSlice([]string{"custom", "home", "other", "work"}, false),
),
},
},
},
},
// TODO: (mbang) Add ValidateDiagFunc for max size when it's allowed on lists
// (https://github.com/hashicorp/terraform-plugin-sdk/issues/156)
"organizations": {
Description: "A list of organizations the user belongs to. The maximum allowed data size is 10Kb.",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cost_center": {
Description: "The cost center of the user's organization.",
Type: schema.TypeString,
Optional: true,
},
"custom_type": {
Description: "If the value of type is custom, this property contains the custom value.",
Type: schema.TypeString,
Optional: true,
},
"department": {
Description: "Specifies the department within the organization, such as sales or engineering.",
Type: schema.TypeString,
Optional: true,
},
"description": {
Description: "The description of the organization.",
Type: schema.TypeString,
Optional: true,
},
"domain": {
Description: "The domain the organization belongs to.",
Type: schema.TypeString,
Optional: true,
},
"full_time_equivalent": {
Description: "The full-time equivalent millipercent within the organization (100000 = 100%)",
Type: schema.TypeInt,
Optional: true,
},
"location": {
Description: "The physical location of the organization. " +
"This does not need to be a fully qualified address.",
Type: schema.TypeString,
Optional: true,
},
"name": {
Description: "The name of the organization.",
Type: schema.TypeString,
Optional: true,
},
"primary": {
Description: "Indicates if this is the user's primary organization. A user may only have " +
"one primary organization.",
Type: schema.TypeBool,
Optional: true,
},
"symbol": {
Description: "Text string symbol of the organization. For example, " +
"the text symbol for Google is GOOG.",
Type: schema.TypeString,
Optional: true,
},
"title": {
Description: "The user's title within the organization. For example, member or engineer.",
Type: schema.TypeString,
Optional: true,
},
"type": {
Description: "The type of organization. " +
"Acceptable values: `domain_only`, `school`, `unknown`, `work`.",
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validation.ToDiagFunc(
validation.StringInSlice([]string{"domain_only", "school", "unknown", "work"}, false),
),
},
},
},
},
"last_login_time": {
Description: "The last time the user logged into the user's account. The value is in ISO 8601 date " +
"and time format. The time is the complete date plus hours, minutes, and seconds " +
"in the form YYYY-MM-DDThh:mm:ssTZD. For example, 2010-04-05T17:30:04+01:00.",
Type: schema.TypeString,
Computed: true,
},
// TODO: (mbang) Add ValidateDiagFunc for max size when it's allowed on lists
// (https://github.com/hashicorp/terraform-plugin-sdk/issues/156)
"phones": {
Description: "A list of the user's phone numbers. The maximum allowed data size is 1Kb.",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"custom_type": {
Description: "If the phone number type is custom, this property contains the custom value " +
"and must be set.",
Type: schema.TypeString,
Optional: true,
},
"primary": {
Description: "Indicates if this is the user's primary phone number. " +
"A user may only have one primary phone number.",
Type: schema.TypeBool,
Optional: true,
},
"type": {
Description: "The type of phone number. " +
"Acceptable values: `assistant`, `callback`, `car`, `company_main` " +
", `custom`, `grand_central`, `home`, `home_fax`, `isdn`, `main`, `mobile`, `other`, " +
"`other_fax`, `pager`, `radio`, `telex`, `tty_tdd`, `work`, `work_fax`, `work_mobile`, " +
"`work_pager`.",
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validation.ToDiagFunc(
validation.StringInSlice([]string{"assistant", "callback", "car", "company_main",
"custom", "grand_central", "home", "home_fax", "isdn", "main", "mobile", "other",
"other_fax", "pager", "radio", "telex", "tty_tdd", "work", "work_fax",
"work_mobile", "work_pager"}, false),
),
},
"value": {
Description: "A human-readable phone number. It may be in any telephone number format.",
Type: schema.TypeString,
Required: true,
},
},
},
},
"suspension_reason": {
Description: "Has the reason a user account is suspended either by the administrator or by Google at " +
"the time of suspension. The property is returned only if the suspended property is true.",
Type: schema.TypeString,
Computed: true,
},
"thumbnail_photo_url": {
Description: "Photo Url of the user.",
Type: schema.TypeString,
Computed: true,
},
// TODO: (mbang) Add ValidateDiagFunc for max size when it's allowed on lists
// (https://github.com/hashicorp/terraform-plugin-sdk/issues/156)
"languages": {
Description: "A list of the user's languages. The maximum allowed data size is 1Kb.",
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"custom_language": {
Description: "Other language. A user can provide their own language name if there is no " +
"corresponding Google III language code. If this is set, LanguageCode can't be set.",
Type: schema.TypeString,
Optional: true,
// TODO: (mbang) https://github.com/hashicorp/terraform-plugin-sdk/issues/470
//ExactlyOneOf: []string{"custom_language", "language_code"},
//ConflictsWith: []string{"custom_language", "preference"},
},
"language_code": {
Description: "Language Code. Should be used for storing Google III LanguageCode string " +
"representation for language. Illegal values cause SchemaException.",
Type: schema.TypeString,
Optional: true,
Default: "en",
// TODO: (mbang) https://github.com/hashicorp/terraform-plugin-sdk/issues/470
//ExactlyOneOf: []string{"custom_language", "language_code"},
},
"preference": {
Description: "If present, controls whether the specified languageCode is the user's " +
"preferred language. Allowed values are `preferred` and `not_preferred`.",
Type: schema.TypeString,
Optional: true,
Default: "preferred",
// TODO: (mbang) https://github.com/hashicorp/terraform-plugin-sdk/issues/470
//ConflictsWith: []string{"custom_language", "preference"},
},
},
},
},
// TODO: (mbang) AtLeastOneOf (https://github.com/hashicorp/terraform-plugin-sdk/issues/470)
"posix_accounts": {
Description: "A list of POSIX account information for the user.",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"account_id": {
Description: "A POSIX account field identifier.",
Type: schema.TypeString,
Optional: true,
},
"gecos": {
Description: "The GECOS (user information) for this account.",
Type: schema.TypeString,
Optional: true,
},
"gid": {
Description: "The default group ID.",
Type: schema.TypeString,
Optional: true,
},
"home_directory": {
Description: "The path to the home directory for this account.",
Type: schema.TypeString,
Optional: true,
},
"operating_system_type": {
Description: "The operating system type for this account. " +
"Acceptable values: `linux`, `unspecified`, `windows`.",
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: validation.ToDiagFunc(
validation.StringInSlice([]string{"linux", "unspecified", "windows"}, false),
),
},
"primary": {
Description: "If this is user's primary account within the SystemId.",
Type: schema.TypeBool,
Optional: true,
},
"shell": {
Description: "The path to the login shell for this account.",
Type: schema.TypeString,
Optional: true,
},
"system_id": {
Description: "System identifier for which account Username or Uid apply to.",
Type: schema.TypeString,
Optional: true,
},
"uid": {
Description: "The POSIX compliant user ID.",
Type: schema.TypeString,
Optional: true,
},
"username": {
Description: "The username of the account.",
Type: schema.TypeString,
Optional: true,
},
},
},
},
"creation_time": {
Description: "The time the user's account was created. The value is in ISO 8601 date and time format. " +
"The time is the complete date plus hours, minutes, and seconds in the form " +
"YYYY-MM-DDThh:mm:ssTZD. For example, 2010-04-05T17:30:04+01:00.",
Type: schema.TypeString,
Computed: true,
},
"non_editable_aliases": {
Description: "asps.list of the user's non-editable alias email addresses. These are typically outside " +
"the account's primary domain or sub-domain.",
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
// TODO: (mbang) Add ValidateDiagFunc for max size when it's allowed on lists
// (https://github.com/hashicorp/terraform-plugin-sdk/issues/156)
"ssh_public_keys": {
Description: "A list of SSH public keys. The maximum allowed data size is 10Kb.",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"expiration_time_usec": {
Description: "An expiration time in microseconds since epoch.",
Type: schema.TypeString,
Optional: true,
},
"fingerprint": {
Description: "A SHA-256 fingerprint of the SSH public key.",
Type: schema.TypeString,
Computed: true,
},
"key": {
Description: "An SSH public key.",
Type: schema.TypeString,
Required: true,
},
},
},
},
// TODO: (mbang) Add ValidateDiagFunc for max size when it's allowed on lists
// (https://github.com/hashicorp/terraform-plugin-sdk/issues/156)
"websites": {
Description: "A list of the user's websites. The maximum allowed data size is 2Kb.",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"custom_type": {
Description: "The custom type. Only used if the type is custom.",
Type: schema.TypeString,
Optional: true,
},
"primary": {
Description: "If this is user's primary website or not.",
Type: schema.TypeBool,
Optional: true,
},
"type": {
Description: "The type or purpose of the website. For example, a website could be labeled " +
"as home or blog. Alternatively, an entry can have a custom type " +
"Custom types must have a customType value. " +
"Acceptable values: `app_install_page`, `blog`, `custom`, `ftp` " +
", `home`, `home_page`, `other`, `profile`, `reservations`, `resume`, `work`.",
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validation.ToDiagFunc(
validation.StringInSlice([]string{"app_install_page", "blog", "custom", "ftp",
"home", "home_page", "other", "profile", "reservations", "resume", "work"},
false),
),
},
"value": {
Description: "The URL of the website.",
Type: schema.TypeString,
Required: true,
},
},
},
},
// TODO: (mbang) Add ValidateDiagFunc for max size when it's allowed on lists
// (https://github.com/hashicorp/terraform-plugin-sdk/issues/156)
"locations": {
Description: "A list of the user's locations. The maximum allowed data size is 10Kb.",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"area": {
Description: "Textual location. This is most useful for display purposes to concisely " +
"describe the location. For example, Mountain View, CA or Near Seattle.",
Type: schema.TypeString,
Optional: true,
},
"building_id": {
Description: "Building identifier.",
Type: schema.TypeString,
Optional: true,
},
"custom_type": {
Description: "If the location type is custom, this property contains the custom value.",
Type: schema.TypeString,
Optional: true,
},
"desk_code": {
Description: "Most specific textual code of individual desk location.",
Type: schema.TypeString,
Optional: true,
},
"floor_name": {
Description: "Floor name/number.",
Type: schema.TypeString,
Optional: true,
},
"floor_section": {
Description: "Floor section. More specific location within the floor. For example, " +
"if a floor is divided into sections A, B, and C, this field would identify one " +
"of those values.",
Type: schema.TypeString,
Optional: true,
},
"type": {
Description: "The location type. " +
"Acceptable values: `custom`, `default`, `desk`",
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validation.ToDiagFunc(
validation.StringInSlice([]string{"custom", "default", "desk"},
false),
),
},
},
},
},
"include_in_global_address_list": {
Description: "Indicates if the user's profile is visible in the Google Workspace global address list " +
"when the contact sharing feature is enabled for the domain.",
Type: schema.TypeBool,
Optional: true,
Default: true,
},
// TODO: (mbang) Add ValidateDiagFunc for max size when it's allowed on lists
// (https://github.com/hashicorp/terraform-plugin-sdk/issues/156)
"keywords": {
Description: "A list of the user's keywords. The maximum allowed data size is 1Kb.",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"custom_type": {
Description: "Custom Type.",
Type: schema.TypeString,
Optional: true,
},
"type": {
Description: "Each entry can have a type which indicates standard type of that entry. " +
"For example, keyword could be of type occupation or outlook. In addition to the " +
"standard type, an entry can have a custom type and can give it any name. Such types " +
"should have the CUSTOM value as type and also have a customType value. " +
"Acceptable values: `custom`, `mission`, `occupation`, `outlook`",
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validation.ToDiagFunc(
validation.StringInSlice([]string{"custom", "mission", "occupation", "outlook"},
false),
),
},
"value": {
Description: "Keyword.",
Type: schema.TypeString,
Required: true,
},
},
},
},
"deletion_time": {
Description: "The time the user's account was deleted. The value is in ISO 8601 date and time format " +
"The time is the complete date plus hours, minutes, and seconds in the form YYYY-MM-DDThh:mm:ssTZD. " +
"For example 2010-04-05T17:30:04+01:00.",
Type: schema.TypeString,
Computed: true,
},
// "gender" is not included in the GET response, currently, so leaving this out for now
"thumbnail_photo_etag": {
Description: "ETag of the user's photo",
Type: schema.TypeString,
Computed: true,
},
// TODO: (mbang) Add ValidateDiagFunc for max size when it's allowed on lists
// (https://github.com/hashicorp/terraform-plugin-sdk/issues/156)
"ims": {
Description: "The user's Instant Messenger (IM) accounts. A user account can have multiple ims " +
"properties. But, only one of these ims properties can be the primary IM contact. " +
"The maximum allowed data size is 2Kb.",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"custom_protocol": {
Description: "If the protocol value is custom_protocol, this property holds the custom " +
"protocol's string.",
Type: schema.TypeString,
Optional: true,
},
"custom_type": {
Description: "If the IM type is custom, this property holds the custom type string.",
Type: schema.TypeString,
Optional: true,
},
"im": {
Description: "The user's IM network ID.",
Type: schema.TypeString,
Optional: true,
},
"primary": {
Description: "If this is the user's primary IM. " +
"Only one entry in the IM list can have a value of true.",
Type: schema.TypeBool,
Optional: true,
},
"protocol": {
Description: "An IM protocol identifies the IM network. " +
"The value can be a custom network or the standard network. " +
"Acceptable values: `aim`, `custom_protocol`, `gtalk`, `icq`, `jabber`, " +
"`msn`, `net_meeting`, `qq`, `skype`, `yahoo`.",
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validation.ToDiagFunc(
validation.StringInSlice([]string{"aim", "custom_protocol", "gtalk", "icq",
"jabber", "msn", "net_meeting", "qq", "skype", "yahoo"}, false),
),
},
"type": {
Description: "Acceptable values: `custom`, `home`, `other`, `work`.",
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validation.ToDiagFunc(
validation.StringInSlice([]string{"custom", "home", "other", "work"}, false),
),
},
},
},
},
"custom_schemas": {
Description: "Custom fields of the user.",
Type: schema.TypeList,
Optional: true,
DiffSuppressFunc: diffSuppressCustomSchemas,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"schema_name": {
Description: "The name of the schema.",
Type: schema.TypeString,
Required: true,
},
"schema_values": {
Description: "JSON encoded map that represents key/value pairs that " +
"correspond to the given schema. ",
Type: schema.TypeMap,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateDiagFunc: validation.ToDiagFunc(
validation.StringIsJSON,
),
},
},
},
},
},
"is_enrolled_in_2_step_verification": {
Description: "Is enrolled in 2-step verification.",
Type: schema.TypeBool,
Computed: true,
},
"is_enforced_in_2_step_verification": {
Description: "Is 2-step verification enforced.",
Type: schema.TypeBool,
Computed: true,
},
"archived": {
Description: "Indicates if user is archived.",
Type: schema.TypeBool,
Optional: true,
},
"org_unit_path": {
Description: "The full path of the parent organization associated with the user. " +
"If the parent organization is the top-level, it is represented as a forward slash (/).",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"recovery_email": {
Description: "Recovery email of the user.",
Type: schema.TypeString,
Optional: true,
},
"recovery_phone": {
Description: "Recovery phone of the user. The phone number must be in the E.164 format, " +
"starting with the plus sign (+). Example: +16506661212.",
Type: schema.TypeString,
Optional: true,
},
},