forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.go
751 lines (621 loc) · 20.4 KB
/
stack.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
package appstream
import (
"bytes"
"context"
"errors"
"fmt"
"log"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/appstream"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)
var (
flagDiffUserSettings = false
)
func ResourceStack() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceStackCreate,
ReadWithoutTimeout: resourceStackRead,
UpdateWithoutTimeout: resourceStackUpdate,
DeleteWithoutTimeout: resourceStackDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Schema: map[string]*schema.Schema{
"access_endpoints": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
MinItems: 1,
MaxItems: 4,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"endpoint_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(appstream.AccessEndpointType_Values(), false),
},
"vpce_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
},
Set: accessEndpointsHash,
},
"application_settings": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Required: true,
},
"settings_group": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(0, 1000),
},
},
},
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
"created_time": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(0, 256),
},
"display_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(0, 100),
},
"embed_host_domains": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
MinItems: 1,
MaxItems: 20,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringLenBetween(0, 128),
},
Set: schema.HashString,
},
"feedback_url": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringLenBetween(0, 100),
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"redirect_url": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringLenBetween(0, 100),
},
"storage_connectors": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"connector_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(appstream.StorageConnectorType_Values(), false),
},
"domains": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 50,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringLenBetween(1, 64),
},
},
"resource_identifier": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringLenBetween(1, 2048),
},
},
},
Set: storageConnectorsHash,
},
"user_settings": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
MinItems: 1,
DiffSuppressFunc: suppressAppsStreamStackUserSettings,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"action": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(appstream.Action_Values(), false),
},
"permission": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(appstream.Permission_Values(), false),
},
},
},
Set: userSettingsHash,
},
"tags": tftags.TagsSchemaForceNew(),
"tags_all": tftags.TagsSchemaComputed(),
},
CustomizeDiff: customdiff.All(
verify.SetTagsDiff,
func(_ context.Context, d *schema.ResourceDiff, meta interface{}) error {
if d.Id() == "" {
return nil
}
rawConfig := d.GetRawConfig()
configApplicationSettings := rawConfig.GetAttr("application_settings")
if configApplicationSettings.IsKnown() && !configApplicationSettings.IsNull() && configApplicationSettings.LengthInt() > 0 {
return nil
}
rawState := d.GetRawState()
stateApplicationSettings := rawState.GetAttr("application_settings")
if stateApplicationSettings.IsKnown() && !stateApplicationSettings.IsNull() && stateApplicationSettings.LengthInt() > 0 {
setting := stateApplicationSettings.Index(cty.NumberIntVal(0))
if setting.IsKnown() && !setting.IsNull() {
enabled := setting.GetAttr("enabled")
if enabled.IsKnown() && !enabled.IsNull() && enabled.True() {
// Trigger a diff
return d.SetNew("application_settings", []map[string]any{
{
"enabled": false,
"settings_group": "",
},
})
}
}
}
return nil
},
func(_ context.Context, d *schema.ResourceDiff, meta interface{}) error {
_, enabled := d.GetOk("application_settings.0.enabled")
v, sg := d.GetOk("application_settings.0.settings_group")
log.Print(v)
if enabled && !sg {
return errors.New("application_settings.settings_group must be set when application_settings.enabled is true")
} else if !enabled && sg {
return errors.New("application_settings.settings_group must not be set when application_settings.enabled is false")
}
return nil
},
),
}
}
func resourceStackCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).AppStreamConn
input := &appstream.CreateStackInput{
Name: aws.String(d.Get("name").(string)),
}
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(tftags.New(d.Get("tags").(map[string]interface{})))
if v, ok := d.GetOk("access_endpoints"); ok {
input.AccessEndpoints = expandAccessEndpoints(v.(*schema.Set).List())
}
if v, ok := d.GetOk("application_settings"); ok {
input.ApplicationSettings = expandApplicationSettings(v.([]interface{}))
}
if v, ok := d.GetOk("description"); ok {
input.Description = aws.String(v.(string))
}
if v, ok := d.GetOk("display_name"); ok {
input.DisplayName = aws.String(v.(string))
}
if v, ok := d.GetOk("embed_host_domains"); ok {
input.EmbedHostDomains = flex.ExpandStringSet(v.(*schema.Set))
}
if v, ok := d.GetOk("feedback_url"); ok {
input.FeedbackURL = aws.String(v.(string))
}
if v, ok := d.GetOk("redirect_url"); ok {
input.RedirectURL = aws.String(v.(string))
}
if v, ok := d.GetOk("storage_connectors"); ok {
input.StorageConnectors = expandStorageConnectors(v.(*schema.Set).List())
}
if v, ok := d.GetOk("user_settings"); ok {
input.UserSettings = expandUserSettings(v.(*schema.Set).List())
}
if len(tags) > 0 {
input.Tags = Tags(tags.IgnoreAWS())
}
var err error
var output *appstream.CreateStackOutput
err = resource.RetryContext(ctx, stackOperationTimeout, func() *resource.RetryError {
output, err = conn.CreateStackWithContext(ctx, input)
if err != nil {
if tfawserr.ErrCodeEquals(err, appstream.ErrCodeResourceNotFoundException) {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if tfresource.TimedOut(err) {
output, err = conn.CreateStackWithContext(ctx, input)
}
if err != nil {
return diag.FromErr(fmt.Errorf("error creating Appstream Stack (%s): %w", d.Id(), err))
}
d.SetId(aws.StringValue(output.Stack.Name))
return resourceStackRead(ctx, d, meta)
}
func resourceStackRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).AppStreamConn
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig
resp, err := conn.DescribeStacksWithContext(ctx, &appstream.DescribeStacksInput{Names: []*string{aws.String(d.Id())}})
if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, appstream.ErrCodeResourceNotFoundException) {
log.Printf("[WARN] Appstream Stack (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}
if err != nil {
return diag.FromErr(fmt.Errorf("error reading Appstream Stack (%s): %w", d.Id(), err))
}
for _, v := range resp.Stacks {
if err = d.Set("access_endpoints", flattenAccessEndpoints(v.AccessEndpoints)); err != nil {
return diag.FromErr(fmt.Errorf("error setting `%s` for AppStream Stack (%s): %w", "access_endpoints", d.Id(), err))
}
if err = d.Set("application_settings", flattenApplicationSettings(v.ApplicationSettings)); err != nil {
return diag.FromErr(fmt.Errorf("error setting `%s` for AppStream Stack (%s): %w", "application_settings", d.Id(), err))
}
d.Set("arn", v.Arn)
d.Set("created_time", aws.TimeValue(v.CreatedTime).Format(time.RFC3339))
d.Set("description", v.Description)
d.Set("display_name", v.DisplayName)
if err = d.Set("embed_host_domains", flex.FlattenStringList(v.EmbedHostDomains)); err != nil {
return diag.FromErr(fmt.Errorf("error setting `%s` for AppStream Stack (%s): %w", "embed_host_domains", d.Id(), err))
}
d.Set("feedback_url", v.FeedbackURL)
d.Set("name", v.Name)
d.Set("redirect_url", v.RedirectURL)
if err = d.Set("storage_connectors", flattenStorageConnectors(v.StorageConnectors)); err != nil {
return diag.FromErr(fmt.Errorf("error setting `%s` for AppStream Stack (%s): %w", "storage_connectors", d.Id(), err))
}
if err = d.Set("user_settings", flattenUserSettings(v.UserSettings)); err != nil {
return diag.FromErr(fmt.Errorf("error setting `%s` for AppStream Stack (%s): %w", "user_settings", d.Id(), err))
}
tg, err := conn.ListTagsForResource(&appstream.ListTagsForResourceInput{
ResourceArn: v.Arn,
})
if err != nil {
return diag.FromErr(fmt.Errorf("error listing stack tags for AppStream Stack (%s): %w", d.Id(), err))
}
tags := KeyValueTags(tg.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig)
if err = d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil {
return diag.FromErr(fmt.Errorf("error setting `%s` for AppStream Stack (%s): %w", "tags", d.Id(), err))
}
if err = d.Set("tags_all", tags.Map()); err != nil {
return diag.FromErr(fmt.Errorf("error setting `%s` for AppStream Stack (%s): %w", "tags_all", d.Id(), err))
}
}
return nil
}
func resourceStackUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).AppStreamConn
input := &appstream.UpdateStackInput{
Name: aws.String(d.Id()),
}
if d.HasChange("access_endpoints") {
input.AccessEndpoints = expandAccessEndpoints(d.Get("access_endpoints").(*schema.Set).List())
}
if d.HasChange("application_settings") {
input.ApplicationSettings = expandApplicationSettings(d.Get("application_settings").([]interface{}))
}
if d.HasChange("description") {
input.Description = aws.String(d.Get("description").(string))
}
if d.HasChange("display_name") {
input.DisplayName = aws.String(d.Get("display_name").(string))
}
if d.HasChange("feedback_url") {
input.FeedbackURL = aws.String(d.Get("feedback_url").(string))
}
if d.HasChange("redirect_url") {
input.RedirectURL = aws.String(d.Get("redirect_url").(string))
}
if d.HasChange("user_settings") {
input.UserSettings = expandUserSettings(d.Get("user_settings").([]interface{}))
}
resp, err := conn.UpdateStack(input)
if err != nil {
diag.FromErr(fmt.Errorf("error updating Appstream Stack (%s): %w", d.Id(), err))
}
if d.HasChange("tags") {
arn := aws.StringValue(resp.Stack.Arn)
o, n := d.GetChange("tags")
if err := UpdateTags(conn, arn, o, n); err != nil {
return diag.FromErr(fmt.Errorf("error updating Appstream Stack tags (%s): %w", d.Id(), err))
}
}
return resourceStackRead(ctx, d, meta)
}
func resourceStackDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).AppStreamConn
log.Printf("[DEBUG] Deleting AppStream Stack: (%s)", d.Id())
_, err := conn.DeleteStackWithContext(ctx, &appstream.DeleteStackInput{
Name: aws.String(d.Id()),
})
if tfawserr.ErrCodeEquals(err, appstream.ErrCodeResourceNotFoundException) {
return nil
}
if err != nil {
return diag.FromErr(fmt.Errorf("error deleting Appstream Stack (%s): %w", d.Id(), err))
}
if _, err = waitStackStateDeleted(ctx, conn, d.Id()); err != nil {
if tfawserr.ErrCodeEquals(err, appstream.ErrCodeResourceNotFoundException) {
return nil
}
return diag.FromErr(fmt.Errorf("error waiting for Appstream Stack (%s) to be deleted: %w", d.Id(), err))
}
if err != nil {
return diag.FromErr(fmt.Errorf("error reading Appstream Stack (%s): %w", d.Id(), err))
}
return nil
}
func expandAccessEndpoint(tfMap map[string]interface{}) *appstream.AccessEndpoint {
if tfMap == nil {
return nil
}
apiObject := &appstream.AccessEndpoint{
EndpointType: aws.String(tfMap["endpoint_type"].(string)),
}
if v, ok := tfMap["vpce_id"]; ok {
apiObject.VpceId = aws.String(v.(string))
}
return apiObject
}
func expandAccessEndpoints(tfList []interface{}) []*appstream.AccessEndpoint {
if len(tfList) == 0 {
return nil
}
var apiObjects []*appstream.AccessEndpoint
for _, tfMapRaw := range tfList {
tfMap, ok := tfMapRaw.(map[string]interface{})
if !ok {
continue
}
apiObject := expandAccessEndpoint(tfMap)
apiObjects = append(apiObjects, apiObject)
}
return apiObjects
}
func flattenAccessEndpoint(apiObject *appstream.AccessEndpoint) map[string]interface{} {
if apiObject == nil {
return nil
}
tfMap := map[string]interface{}{}
tfMap["endpoint_type"] = aws.StringValue(apiObject.EndpointType)
tfMap["vpce_id"] = aws.StringValue(apiObject.VpceId)
return tfMap
}
func flattenAccessEndpoints(apiObjects []*appstream.AccessEndpoint) []map[string]interface{} {
if len(apiObjects) == 0 {
return nil
}
var tfList []map[string]interface{}
for _, apiObject := range apiObjects {
if apiObject == nil {
continue
}
tfList = append(tfList, flattenAccessEndpoint(apiObject))
}
return tfList
}
func expandApplicationSettings(tfList []interface{}) *appstream.ApplicationSettings {
if len(tfList) == 0 {
return &appstream.ApplicationSettings{
Enabled: aws.Bool(false),
}
}
tfMap := tfList[0].(map[string]interface{})
apiObject := &appstream.ApplicationSettings{
Enabled: aws.Bool(tfMap["enabled"].(bool)),
}
if v, ok := tfMap["settings_group"]; ok {
apiObject.SettingsGroup = aws.String(v.(string))
}
return apiObject
}
func flattenApplicationSetting(apiObject *appstream.ApplicationSettingsResponse) map[string]interface{} {
if apiObject == nil {
return nil
}
return map[string]interface{}{
"enabled": aws.BoolValue(apiObject.Enabled),
"settings_group": aws.StringValue(apiObject.SettingsGroup),
}
}
func flattenApplicationSettings(apiObject *appstream.ApplicationSettingsResponse) []interface{} {
if apiObject == nil {
return nil
}
var tfList []interface{}
tfList = append(tfList, flattenApplicationSetting(apiObject))
return tfList
}
func expandStorageConnector(tfMap map[string]interface{}) *appstream.StorageConnector {
if tfMap == nil {
return nil
}
apiObject := &appstream.StorageConnector{
ConnectorType: aws.String(tfMap["connector_type"].(string)),
}
if v, ok := tfMap["domains"]; ok && len(v.([]interface{})) > 0 {
apiObject.Domains = flex.ExpandStringList(v.([]interface{}))
}
if v, ok := tfMap["resource_identifier"]; ok && v.(string) != "" {
apiObject.ResourceIdentifier = aws.String(v.(string))
}
return apiObject
}
func expandStorageConnectors(tfList []interface{}) []*appstream.StorageConnector {
if len(tfList) == 0 {
return nil
}
var apiObjects []*appstream.StorageConnector
for _, tfMapRaw := range tfList {
tfMap, ok := tfMapRaw.(map[string]interface{})
if !ok {
continue
}
apiObject := expandStorageConnector(tfMap)
if apiObject == nil {
continue
}
apiObjects = append(apiObjects, apiObject)
}
return apiObjects
}
func flattenStorageConnector(apiObject *appstream.StorageConnector) map[string]interface{} {
if apiObject == nil {
return nil
}
tfMap := map[string]interface{}{}
tfMap["connector_type"] = aws.StringValue(apiObject.ConnectorType)
tfMap["domains"] = aws.StringValueSlice(apiObject.Domains)
tfMap["resource_identifier"] = aws.StringValue(apiObject.ResourceIdentifier)
return tfMap
}
func flattenStorageConnectors(apiObjects []*appstream.StorageConnector) []map[string]interface{} {
if len(apiObjects) == 0 {
return nil
}
var tfList []map[string]interface{}
for _, apiObject := range apiObjects {
if apiObject == nil {
continue
}
tfList = append(tfList, flattenStorageConnector(apiObject))
}
return tfList
}
func expandUserSetting(tfMap map[string]interface{}) *appstream.UserSetting {
if tfMap == nil {
return nil
}
apiObject := &appstream.UserSetting{
Action: aws.String(tfMap["action"].(string)),
Permission: aws.String(tfMap["permission"].(string)),
}
return apiObject
}
func expandUserSettings(tfList []interface{}) []*appstream.UserSetting {
if len(tfList) == 0 {
return nil
}
var apiObjects []*appstream.UserSetting
for _, tfMapRaw := range tfList {
tfMap, ok := tfMapRaw.(map[string]interface{})
if !ok {
continue
}
apiObject := expandUserSetting(tfMap)
if apiObject == nil {
continue
}
apiObjects = append(apiObjects, apiObject)
}
return apiObjects
}
func flattenUserSetting(apiObject *appstream.UserSetting) map[string]interface{} {
if apiObject == nil {
return nil
}
tfMap := map[string]interface{}{}
tfMap["action"] = aws.StringValue(apiObject.Action)
tfMap["permission"] = aws.StringValue(apiObject.Permission)
return tfMap
}
func flattenUserSettings(apiObjects []*appstream.UserSetting) []map[string]interface{} {
if len(apiObjects) == 0 {
return nil
}
var tfList []map[string]interface{}
for _, apiObject := range apiObjects {
if apiObject == nil {
continue
}
tfList = append(tfList, flattenUserSetting(apiObject))
}
return tfList
}
func suppressAppsStreamStackUserSettings(k, old, new string, d *schema.ResourceData) bool {
count := len(d.Get("user_settings").(*schema.Set).List())
defaultCount := len(appstream.Action_Values())
if count == defaultCount {
flagDiffUserSettings = false
}
if count != defaultCount && (fmt.Sprintf("%d", count) == new && fmt.Sprintf("%d", defaultCount) == old) {
flagDiffUserSettings = true
}
return flagDiffUserSettings
}
func accessEndpointsHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
buf.WriteString(m["endpoint_type"].(string))
buf.WriteString(m["vpce_id"].(string))
return create.StringHashcode(buf.String())
}
func storageConnectorsHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
buf.WriteString(m["connector_type"].(string))
buf.WriteString(fmt.Sprintf("%+v", m["domains"].([]interface{})))
buf.WriteString(m["resource_identifier"].(string))
return create.StringHashcode(buf.String())
}
func userSettingsHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
buf.WriteString(m["action"].(string))
buf.WriteString(m["permission"].(string))
return create.StringHashcode(buf.String())
}