forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
active_directory_domain_service_resource.go
774 lines (668 loc) · 23.8 KB
/
active_directory_domain_service_resource.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
package domainservices
import (
"context"
"fmt"
"log"
"strings"
"time"
"github.com/Azure/azure-sdk-for-go/services/domainservices/mgmt/2020-01-01/aad"
"github.com/hashicorp/go-azure-helpers/lang/response"
azValidate "github.com/kevinklinger/terraform-provider-azurerm/v2/helpers/validate"
networkValidate "github.com/kevinklinger/terraform-provider-azurerm/v2/internal/services/network/validate"
"github.com/kevinklinger/terraform-provider-azurerm/v2/helpers/azure"
"github.com/kevinklinger/terraform-provider-azurerm/v2/helpers/tf"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/clients"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/location"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/locks"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/services/domainservices/parse"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/tags"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/tf/pluginsdk"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/tf/validation"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/timeouts"
"github.com/kevinklinger/terraform-provider-azurerm/v2/utils"
)
const DomainServiceResourceName = "azurerm_active_directory_domain_service"
func resourceActiveDirectoryDomainService() *pluginsdk.Resource {
return &pluginsdk.Resource{
Create: resourceActiveDirectoryDomainServiceCreateUpdate,
Read: resourceActiveDirectoryDomainServiceRead,
Update: resourceActiveDirectoryDomainServiceCreateUpdate,
Delete: resourceActiveDirectoryDomainServiceDelete,
Timeouts: &pluginsdk.ResourceTimeout{
Create: pluginsdk.DefaultTimeout(3 * time.Hour),
Read: pluginsdk.DefaultTimeout(5 * time.Minute),
Update: pluginsdk.DefaultTimeout(2 * time.Hour),
Delete: pluginsdk.DefaultTimeout(1 * time.Hour),
},
Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error {
_, err := parse.DomainServiceID(id)
return err
}),
Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty, // TODO: proper validation
},
"location": azure.SchemaLocation(),
"resource_group_name": azure.SchemaResourceGroupName(),
"domain_name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty, // TODO: proper validation, first prefix must be 15 chars or less
},
"initial_replica_set": {
Type: pluginsdk.TypeList,
Required: true,
MinItems: 1,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"domain_controller_ip_addresses": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},
"external_access_ip_address": {
Type: pluginsdk.TypeString,
Computed: true,
},
"id": {
Type: pluginsdk.TypeString,
Computed: true,
},
// location is computed here
"location": azure.SchemaLocationForDataSource(),
"service_status": {
Type: pluginsdk.TypeString,
Computed: true,
},
"subnet_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: networkValidate.SubnetID,
},
},
},
},
"sku": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
"Standard",
"Enterprise",
"Premium",
}, false),
},
"filtered_sync_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
"notifications": {
Type: pluginsdk.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"additional_recipients": {
Type: pluginsdk.TypeSet,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.StringIsNotWhiteSpace,
},
},
"notify_dc_admins": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
"notify_global_admins": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
},
},
},
"secure_ldap": {
Type: pluginsdk.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"enabled": {
Type: pluginsdk.TypeBool,
Required: true,
},
"external_access_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
"pfx_certificate": {
Type: pluginsdk.TypeString,
Required: true,
Sensitive: true,
ValidateFunc: azValidate.Base64EncodedString,
},
"pfx_certificate_password": {
Type: pluginsdk.TypeString,
Required: true,
Sensitive: true,
},
"certificate_expiry": {
Type: pluginsdk.TypeString,
Computed: true,
},
"certificate_thumbprint": {
Type: pluginsdk.TypeString,
Computed: true,
},
"public_certificate": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
},
"security": {
Type: pluginsdk.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"ntlm_v1_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
"sync_kerberos_passwords": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
"sync_ntlm_passwords": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
"sync_on_prem_passwords": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
"tls_v1_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
},
},
},
"tags": tags.Schema(),
"deployment_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
"resource_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
"sync_owner": {
Type: pluginsdk.TypeString,
Computed: true,
},
"tenant_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
"version": {
Type: pluginsdk.TypeInt,
Computed: true,
},
},
}
}
func resourceActiveDirectoryDomainServiceCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).DomainServices.DomainServicesClient
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()
name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)
resourceErrorName := fmt.Sprintf("Domain Service (Name: %q, Resource Group: %q)", name, resourceGroup)
locks.ByName(name, DomainServiceResourceName)
defer locks.UnlockByName(name, DomainServiceResourceName)
// If this is a new resource, we cannot determine the resource ID until after it has been created since we need to
// know the ID of the first replica set.
var id *parse.DomainServiceId
if d.IsNewResource() {
existing, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if !utils.ResponseWasNotFound(existing.Response) {
return fmt.Errorf("checking for presence of existing %s: %s", resourceErrorName, err)
}
}
if existing.ID != nil && *existing.ID != "" {
// Parse the replica sets and assume the first one returned to be the initial replica set
// This is a best effort and the user can choose any replica set if they structure their config accordingly
props := existing.DomainServiceProperties
if props == nil {
return fmt.Errorf("checking for presence of existing %s: API response contained nil or missing properties", resourceErrorName)
}
replicaSets := flattenDomainServiceReplicaSets(props.ReplicaSets)
if len(replicaSets) == 0 {
return fmt.Errorf("checking for presence of existing %s: API response contained nil or missing replica set details", resourceErrorName)
}
initialReplicaSetId := replicaSets[0].(map[string]interface{})["id"].(string)
id := parse.NewDomainServiceID(client.SubscriptionID, resourceGroup, name, initialReplicaSetId)
return tf.ImportAsExistsError(DomainServiceResourceName, id.ID())
}
} else {
var err error
id, err = parse.DomainServiceID(d.Id())
if err != nil {
return fmt.Errorf("preparing update for %s: %+v", resourceErrorName, err)
}
if id == nil {
return fmt.Errorf("preparing update for %s: resource ID could not be parsed", resourceErrorName)
}
}
loc := location.Normalize(d.Get("location").(string))
filteredSync := aad.FilteredSyncDisabled
if d.Get("filtered_sync_enabled").(bool) {
filteredSync = aad.FilteredSyncDisabled
}
domainService := aad.DomainService{
DomainServiceProperties: &aad.DomainServiceProperties{
DomainName: utils.String(d.Get("domain_name").(string)),
DomainSecuritySettings: expandDomainServiceSecurity(d.Get("security").([]interface{})),
FilteredSync: filteredSync,
LdapsSettings: expandDomainServiceLdaps(d.Get("secure_ldap").([]interface{})),
NotificationSettings: expandDomainServiceNotifications(d.Get("notifications").([]interface{})),
Sku: utils.String(d.Get("sku").(string)),
},
Location: utils.String(loc),
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}
if d.IsNewResource() {
// On resource creation, specify the initial replica set.
// No provision is made for changing the initial replica set, it should remain intact for the resource to function properly
replicaSets := []aad.ReplicaSet{
{
Location: utils.String(loc),
SubnetID: utils.String(d.Get("initial_replica_set.0.subnet_id").(string)),
},
}
domainService.DomainServiceProperties.ReplicaSets = &replicaSets
}
future, err := client.CreateOrUpdate(ctx, resourceGroup, name, domainService)
if err != nil {
return fmt.Errorf("creating/updating %s: %+v", resourceErrorName, err)
}
if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting for %s: %+v", resourceErrorName, err)
}
// Retrieve the domain service to discover the unique ID for the initial replica set, which should not subsequently change
if d.IsNewResource() {
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("retrieving %s after creating: %+v", resourceErrorName, err)
}
props := resp.DomainServiceProperties
if props == nil {
return fmt.Errorf("%s returned with no properties", resourceErrorName)
}
if props.ReplicaSets == nil {
return fmt.Errorf("%s returned with no replica set details", resourceErrorName)
}
replicaSets := flattenDomainServiceReplicaSets(props.ReplicaSets)
if replicaSetCount := len(replicaSets); replicaSetCount != 1 {
return fmt.Errorf("unexpected number of replica sets for %s: expected 1, saw %d", resourceErrorName, replicaSetCount)
}
// Once we know the initial replica set ID, we can build a resource ID
initialReplicaSetId := replicaSets[0].(map[string]interface{})["id"].(string)
newId := parse.NewDomainServiceID(client.SubscriptionID, resourceGroup, name, initialReplicaSetId)
id = &newId
d.SetId(id.ID())
if err := d.Set("initial_replica_set", []interface{}{replicaSets[0]}); err != nil {
return fmt.Errorf("setting `initial_replica_set` after creating resource: %+v", err)
}
}
if id == nil {
return fmt.Errorf("after creating/updating %s: id was unexpectedly nil", resourceErrorName)
}
// A fully deployed domain service has 2 domain controllers per replica set, but the create operation completes early before the DCs are online.
// The domain service is still provisioning and further operations are blocked until both DCs are up and ready.
timeout, _ := ctx.Deadline()
stateConf := &pluginsdk.StateChangeConf{
Pending: []string{"pending"},
Target: []string{"available"},
Refresh: domainServiceControllerRefreshFunc(ctx, client, *id, false),
Delay: 1 * time.Minute,
PollInterval: 1 * time.Minute,
Timeout: time.Until(timeout),
}
if _, err := stateConf.WaitForStateContext(ctx); err != nil {
return fmt.Errorf("waiting for both domain controllers to become available in initial replica set for %s: %+v", id, err)
}
return resourceActiveDirectoryDomainServiceRead(d, meta)
}
func resourceActiveDirectoryDomainServiceRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).DomainServices.DomainServicesClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()
id, err := parse.DomainServiceID(d.Id())
if err != nil {
return err
}
resp, err := client.Get(ctx, id.ResourceGroup, id.Name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
d.SetId("")
return nil
}
return err
}
d.Set("name", id.Name)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("resource_id", resp.ID)
loc := location.NormalizeNilable(resp.Location)
d.Set("location", loc)
if props := resp.DomainServiceProperties; props != nil {
d.Set("deployment_id", props.DeploymentID)
d.Set("domain_name", props.DomainName)
d.Set("sync_owner", props.SyncOwner)
d.Set("tenant_id", props.TenantID)
d.Set("version", props.Version)
d.Set("filtered_sync_enabled", false)
if props.FilteredSync == aad.FilteredSyncEnabled {
d.Set("filtered_sync_enabled", true)
}
d.Set("sku", props.Sku)
if err := d.Set("notifications", flattenDomainServiceNotifications(props.NotificationSettings)); err != nil {
return fmt.Errorf("setting `notifications`: %+v", err)
}
var initialReplicaSet interface{}
replicaSets := flattenDomainServiceReplicaSets(props.ReplicaSets)
// Determine the initial replica set. This is why we need to include InitialReplicaSetId in the resource ID,
// without it we would not be able to reliably support importing.
for _, replicaSetRaw := range replicaSets {
replicaSet := replicaSetRaw.(map[string]interface{})
if replicaSet["id"].(string) == id.InitialReplicaSetIdName {
initialReplicaSet = replicaSetRaw
break
}
}
if initialReplicaSet == nil {
// It's safest to error out here, since we don't want to wipe the initial replica set from state if it was deleted manually
return fmt.Errorf("reading %s: could not determine initial replica set from API response", id)
}
if err := d.Set("initial_replica_set", []interface{}{initialReplicaSet}); err != nil {
return fmt.Errorf("setting `initial_replica_set`: %+v", err)
}
if err := d.Set("secure_ldap", flattenDomainServiceLdaps(d, props.LdapsSettings, false)); err != nil {
return fmt.Errorf("setting `secure_ldap`: %+v", err)
}
if err := d.Set("security", flattenDomainServiceSecurity(props.DomainSecuritySettings)); err != nil {
return fmt.Errorf("setting `security`: %+v", err)
}
}
return tags.FlattenAndSet(d, resp.Tags)
}
func resourceActiveDirectoryDomainServiceDelete(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).DomainServices.DomainServicesClient
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
defer cancel()
id, err := parse.DomainServiceID(d.Id())
if err != nil {
return err
}
future, err := client.Delete(ctx, id.ResourceGroup, id.Name)
if err != nil {
return fmt.Errorf("deleting %s: %+v", id, err)
}
if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
if !response.WasNotFound(future.Response()) {
return fmt.Errorf("waiting for deletion of %s: %+v", id, err)
}
}
return nil
}
func domainServiceControllerRefreshFunc(ctx context.Context, client *aad.DomainServicesClient, id parse.DomainServiceId, deleting bool) pluginsdk.StateRefreshFunc {
return func() (interface{}, string, error) {
log.Printf("[DEBUG] Waiting for domain controllers to deploy...")
resp, err := client.Get(ctx, id.ResourceGroup, id.Name)
if err != nil {
return nil, "error", err
}
if resp.DomainServiceProperties == nil || resp.DomainServiceProperties.ReplicaSets == nil || len(*resp.DomainServiceProperties.ReplicaSets) == 0 {
return nil, "error", fmt.Errorf("API error: `replicaSets` was not returned")
}
// Loop through all replica sets and ensure they are running and each have two available domain controllers
for _, repl := range *resp.DomainServiceProperties.ReplicaSets {
if repl.ServiceStatus == nil {
return resp, "pending", nil
}
switch {
case !deleting && strings.EqualFold(*repl.ServiceStatus, "TearingDown"):
// Sometimes a service error will cause the replica set, or resource, to self destruct
return resp, "error", fmt.Errorf("service error: a replica set is unexpectedly tearing down")
case strings.EqualFold(*repl.ServiceStatus, "Failed"):
// If a replica set enters a failed state, it needs manual intervention
return resp, "error", fmt.Errorf("service error: a replica set has entered a Failed state and must be recovered or deleted manually")
case !strings.EqualFold(*repl.ServiceStatus, "Running"):
// If it's not yet running, it isn't ready
return resp, "pending", nil
case repl.DomainControllerIPAddress == nil || len(*repl.DomainControllerIPAddress) < 2:
// When a domain controller is online, its IP address will be returned. We're looking for 2 active domain controllers.
return resp, "pending", nil
}
}
return resp, "available", nil
}
}
func expandDomainServiceLdaps(input []interface{}) (ldaps *aad.LdapsSettings) {
ldaps = &aad.LdapsSettings{
Ldaps: aad.LdapsDisabled,
}
if len(input) > 0 {
v := input[0].(map[string]interface{})
if v["enabled"].(bool) {
ldaps.Ldaps = aad.LdapsEnabled
}
ldaps.PfxCertificate = utils.String(v["pfx_certificate"].(string))
ldaps.PfxCertificatePassword = utils.String(v["pfx_certificate_password"].(string))
if v["external_access_enabled"].(bool) {
ldaps.ExternalAccess = aad.Enabled
} else {
ldaps.ExternalAccess = aad.Disabled
}
}
return
}
func expandDomainServiceNotifications(input []interface{}) *aad.NotificationSettings {
if len(input) == 0 {
return nil
}
v := input[0].(map[string]interface{})
additionalRecipients := make([]string, 0)
if ar, ok := v["additional_recipients"]; ok {
for _, r := range ar.(*pluginsdk.Set).List() {
additionalRecipients = append(additionalRecipients, r.(string))
}
}
notifyDcAdmins := aad.NotifyDcAdminsDisabled
if n, ok := v["notify_dc_admins"]; ok && n.(bool) {
notifyDcAdmins = aad.NotifyDcAdminsEnabled
}
notifyGlobalAdmins := aad.NotifyGlobalAdminsDisabled
if n, ok := v["notify_global_admins"]; ok && n.(bool) {
notifyGlobalAdmins = aad.NotifyGlobalAdminsEnabled
}
return &aad.NotificationSettings{
AdditionalRecipients: &additionalRecipients,
NotifyDcAdmins: notifyDcAdmins,
NotifyGlobalAdmins: notifyGlobalAdmins,
}
}
func expandDomainServiceSecurity(input []interface{}) *aad.DomainSecuritySettings {
if len(input) == 0 {
return nil
}
v := input[0].(map[string]interface{})
ntlmV1 := aad.NtlmV1Disabled
syncKerberosPasswords := aad.SyncKerberosPasswordsDisabled
syncNtlmPasswords := aad.SyncNtlmPasswordsDisabled
syncOnPremPasswords := aad.SyncOnPremPasswordsDisabled
tlsV1 := aad.TLSV1Disabled
if v["ntlm_v1_enabled"].(bool) {
ntlmV1 = aad.NtlmV1Enabled
}
if v["sync_kerberos_passwords"].(bool) {
syncKerberosPasswords = aad.SyncKerberosPasswordsEnabled
}
if v["sync_ntlm_passwords"].(bool) {
syncNtlmPasswords = aad.SyncNtlmPasswordsEnabled
}
if v["sync_on_prem_passwords"].(bool) {
syncOnPremPasswords = aad.SyncOnPremPasswordsEnabled
}
if v["tls_v1_enabled"].(bool) {
tlsV1 = aad.TLSV1Enabled
}
return &aad.DomainSecuritySettings{
NtlmV1: ntlmV1,
SyncKerberosPasswords: syncKerberosPasswords,
SyncNtlmPasswords: syncNtlmPasswords,
SyncOnPremPasswords: syncOnPremPasswords,
TLSV1: tlsV1,
}
}
func flattenDomainServiceLdaps(d *pluginsdk.ResourceData, input *aad.LdapsSettings, dataSource bool) []interface{} {
result := map[string]interface{}{
"enabled": false,
"external_access_enabled": false,
"certificate_expiry": "",
"certificate_thumbprint": "",
"public_certificate": "",
}
if !dataSource {
// Read pfx_certificate and pfx_certificate_password from existing state since it's not returned
result["pfx_certificate"] = ""
if v, ok := d.GetOk("secure_ldap.0.pfx_certificate"); ok {
result["pfx_certificate"] = v.(string)
}
result["pfx_certificate_password"] = ""
if v, ok := d.GetOk("secure_ldap.0.pfx_certificate_password"); ok {
result["pfx_certificate_password"] = v.(string)
}
}
if input != nil {
if input.ExternalAccess == aad.Enabled {
result["external_access_enabled"] = true
}
if input.Ldaps == aad.LdapsEnabled {
result["enabled"] = true
}
if v := input.CertificateNotAfter; v != nil {
result["certificate_expiry"] = v.Format(time.RFC3339)
}
if v := input.CertificateThumbprint; v != nil {
result["certificate_thumbprint"] = *v
}
if v := input.PublicCertificate; v != nil {
result["public_certificate"] = *v
}
}
return []interface{}{result}
}
func flattenDomainServiceNotifications(input *aad.NotificationSettings) []interface{} {
if input == nil {
return make([]interface{}, 0)
}
result := map[string]interface{}{
"additional_recipients": make([]string, 0),
"notify_dc_admins": false,
"notify_global_admins": false,
}
if input.AdditionalRecipients != nil {
result["additional_recipients"] = *input.AdditionalRecipients
}
if input.NotifyDcAdmins == aad.NotifyDcAdminsEnabled {
result["notify_dc_admins"] = true
}
if input.NotifyGlobalAdmins == aad.NotifyGlobalAdminsEnabled {
result["notify_global_admins"] = true
}
return []interface{}{result}
}
func flattenDomainServiceReplicaSets(input *[]aad.ReplicaSet) (ret []interface{}) {
if input == nil {
return
}
for _, in := range *input {
repl := map[string]interface{}{
"domain_controller_ip_addresses": make([]string, 0),
"external_access_ip_address": "",
"location": location.NormalizeNilable(in.Location),
"id": "",
"service_status": "",
"subnet_id": "",
}
if in.DomainControllerIPAddress != nil {
repl["domain_controller_ip_addresses"] = *in.DomainControllerIPAddress
}
if in.ExternalAccessIPAddress != nil {
repl["external_access_ip_address"] = *in.ExternalAccessIPAddress
}
if in.ReplicaSetID != nil {
repl["id"] = *in.ReplicaSetID
}
if in.ServiceStatus != nil {
repl["service_status"] = *in.ServiceStatus
}
if in.SubnetID != nil {
repl["subnet_id"] = *in.SubnetID
}
ret = append(ret, repl)
}
return
}
func flattenDomainServiceSecurity(input *aad.DomainSecuritySettings) []interface{} {
if input == nil {
return make([]interface{}, 0)
}
result := map[string]bool{
"ntlm_v1_enabled": false,
"sync_kerberos_passwords": false,
"sync_ntlm_passwords": false,
"sync_on_prem_passwords": false,
"tls_v1_enabled": false,
}
if input.NtlmV1 == aad.NtlmV1Enabled {
result["ntlm_v1_enabled"] = true
}
if input.SyncKerberosPasswords == aad.SyncKerberosPasswordsEnabled {
result["sync_kerberos_passwords"] = true
}
if input.SyncNtlmPasswords == aad.SyncNtlmPasswordsEnabled {
result["sync_ntlm_passwords"] = true
}
if input.SyncOnPremPasswords == aad.SyncOnPremPasswordsEnabled {
result["sync_on_prem_passwords"] = true
}
if input.TLSV1 == aad.TLSV1Enabled {
result["tls_v1_enabled"] = true
}
return []interface{}{result}
}