-
Notifications
You must be signed in to change notification settings - Fork 649
/
resource_ibm_is_share.go
1835 lines (1721 loc) · 66.2 KB
/
resource_ibm_is_share.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
// Copyright IBM Corp. 2021 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package vpc
import (
"context"
"fmt"
"log"
"os"
"strings"
"time"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate"
"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/IBM/go-sdk-core/v5/core"
"github.com/IBM/vpc-go-sdk/vpcv1"
)
const (
isFileShareAccessTags = "access_tags"
isFileShareTags = "tags"
IsFileShareReplicationRoleNone = "none"
IsFileShareReplicationRoleSource = "source"
IsFileShareReplicationRoleReplica = "replica"
)
func ResourceIbmIsShare() *schema.Resource {
return &schema.Resource{
CreateContext: resourceIbmIsShareCreate,
ReadContext: resourceIbmIsShareRead,
UpdateContext: resourceIbmIsShareUpdate,
DeleteContext: resourceIbmIsShareDelete,
Importer: &schema.ResourceImporter{},
CustomizeDiff: customdiff.All(
customdiff.Sequence(
func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
return flex.ResourceTagsCustomizeDiff(diff)
},
),
customdiff.Sequence(
func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
return flex.ResourceValidateAccessTags(diff, v)
},
),
),
Schema: map[string]*schema.Schema{
"encryption_key": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
Description: "The CRN of the key to use for encrypting this file share.If no encryption key is provided, the share will not be encrypted.",
},
"initial_owner": {
Type: schema.TypeList,
Optional: true,
MinItems: 1,
MaxItems: 1,
RequiredWith: []string{"size"},
ForceNew: true,
Description: "The owner assigned to the file share at creation.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"gid": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Description: "The initial group identifier for the file share.",
},
"uid": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Description: "The initial user identifier for the file share.",
},
},
},
},
"resource_group": {
Type: schema.TypeString,
Optional: true,
RequiredWith: []string{"size"},
ForceNew: true,
Computed: true,
Description: "The unique identifier of the resource group to use. If unspecified, the account's [default resourcegroup](https://cloud.ibm.com/apidocs/resource-manager#introduction) is used.",
},
"access_control_mode": {
Type: schema.TypeString,
Optional: true,
RequiredWith: []string{"size"},
Computed: true,
Description: "The access control mode for the share:",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ExactlyOneOf: []string{"size", "source_share", "source_share_crn"},
ConflictsWith: []string{"replication_cron_spec", "source_share", "source_share_crn"},
ValidateFunc: validate.InvokeValidator("ibm_is_share", "size"),
Description: "The size of the file share rounded up to the next gigabyte.",
},
"mount_targets": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Description: "The share targets for this file share.Share targets mounted from a replica must be mounted read-only.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "ID of this mount target",
},
"href": {
Type: schema.TypeString,
Computed: true,
Description: "Href of this mount target",
},
"transit_encryption": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The transit encryption mode.",
},
"name": {
Type: schema.TypeString,
Required: true,
Description: "The user-defined name for this share target. Names must be unique within the share the share target resides in. If unspecified, the name will be a hyphenated list of randomly-selected words.",
},
"virtual_network_interface": {
Type: schema.TypeList,
Optional: true,
Description: "VNI for mount target.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"crn": {
Type: schema.TypeString,
Computed: true,
Description: "CRN of virtual network interface",
},
"href": {
Type: schema.TypeString,
Computed: true,
Description: "href of virtual network interface",
},
"id": {
Type: schema.TypeString,
Computed: true,
Description: "ID of this VNI",
},
"name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Name of this VNI",
},
"primary_ip": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Description: "VNI for mount target.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"reserved_ip": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "ID of reserved IP",
},
"address": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The IP address to reserve, which must not already be reserved on the subnet.",
},
"auto_delete": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Indicates whether this reserved IP member will be automatically deleted when either target is deleted, or the reserved IP is unbound.",
},
"name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Name for reserved IP",
},
"resource_type": {
Type: schema.TypeString,
Computed: true,
Description: "Resource type of primary ip",
},
"href": {
Type: schema.TypeString,
Computed: true,
Description: "href of primary ip",
},
},
},
},
"resource_group": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Resource group id",
},
"resource_type": {
Type: schema.TypeString,
Computed: true,
Description: "Resource type of primary ip",
},
"security_groups": {
Type: schema.TypeSet,
Computed: true,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Description: "The security groups to use for this virtual network interface.",
},
"subnet": {
Type: schema.TypeString,
Optional: true,
Description: "The associated subnet. Required if primary_ip is not specified.",
},
},
},
},
"resource_type": {
Type: schema.TypeString,
Computed: true,
Description: "Resource type of mount target",
},
"vpc": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The unique identifier of the VPC in which instances can mount the file share using this share target.This property will be removed in a future release.The `subnet` property should be used instead.",
},
},
},
},
"iops": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validate.InvokeValidator("ibm_is_share", "iops"),
Description: "The maximum input/output operation performance bandwidth per second for the file share.",
},
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.InvokeValidator("ibm_is_share", "name"),
Description: "The unique user-defined name for this file share. If unspecified, the name will be a hyphenated list of randomly-selected words.",
},
"profile": {
Type: schema.TypeString,
Required: true,
Description: "The globally unique name for this share profile.",
},
"replica_share": &schema.Schema{
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
ConflictsWith: []string{"source_share"},
Description: "Configuration for a replica file share to create and associate with this file share. Ifunspecified, a replica may be subsequently added by creating a new file share with a`source_share` referencing this file share.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"crn": {
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this replica share.",
},
"href": {
Type: schema.TypeString,
Computed: true,
Description: "The href for this replica share.",
},
"id": {
Type: schema.TypeString,
Computed: true,
Description: "The ID of this replica file share.",
},
"iops": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validate.InvokeValidator("ibm_is_share", "iops"),
Description: "The maximum input/output operation per second (IOPS) for the file share.",
},
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.InvokeValidator("ibm_is_share", "name"),
Description: "The unique user-defined name for this file share.",
},
"profile": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "Share profile name.",
},
"replication_cron_spec": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "The cron specification for the file share replication schedule.Replication of a share can be scheduled to occur at most once per hour.",
},
"replication_role": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The replication role of the file share.",
},
"replication_status": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The replication status of the file share.",
},
"replication_status_reasons": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The reasons for the current replication status.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"code": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "A snake case string succinctly identifying the status reason.",
},
"message": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "An explanation of the status reason.",
},
"more_info": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about this status reason.",
},
},
},
},
"mount_targets": &schema.Schema{
Type: schema.TypeList,
Optional: true,
Computed: true,
Description: "The share targets for this replica file share.Share targets mounted from a replica must be mounted read-only.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"href": {
Type: schema.TypeString,
Computed: true,
Description: "href of mount target",
},
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "ID of this share target.",
},
"name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The user-defined name for this share target. Names must be unique within the share the share target resides in. If unspecified, the name will be a hyphenated list of randomly-selected words.",
},
"virtual_network_interface": {
Type: schema.TypeList,
Optional: true,
Description: "VNI for mount target.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"crn": {
Type: schema.TypeString,
Computed: true,
Description: "CRN of virtual network interface",
},
"href": {
Type: schema.TypeString,
Computed: true,
Description: "href of virtual network interface",
},
"id": {
Type: schema.TypeString,
Computed: true,
Description: "ID of this VNI",
},
"name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Name of this VNI",
},
"primary_ip": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Description: "VNI for mount target.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"reserved_ip": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "ID of reserved IP",
},
"address": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The IP address to reserve, which must not already be reserved on the subnet.",
},
"auto_delete": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Indicates whether this reserved IP member will be automatically deleted when either target is deleted, or the reserved IP is unbound.",
},
"name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Name for reserved IP",
},
"resource_type": {
Type: schema.TypeString,
Computed: true,
Description: "Resource type of primary ip",
},
"href": {
Type: schema.TypeString,
Computed: true,
Description: "href of primary ip",
},
},
},
},
"resource_group": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Resource group id",
},
"resource_type": {
Type: schema.TypeString,
Computed: true,
Description: "Resource type of primary ip",
},
"security_groups": {
Type: schema.TypeSet,
Computed: true,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Description: "The security groups to use for this virtual network interface.",
},
"subnet": {
Type: schema.TypeString,
Optional: true,
Description: "The associated subnet. Required if primary_ip is not specified.",
},
},
},
},
"resource_type": {
Type: schema.TypeString,
Computed: true,
Description: "Resource type of virtual network interface",
},
"vpc": {
Type: schema.TypeString,
Optional: true,
Description: "The ID of the VPC in which instances can mount the file share using this share target.This property will be removed in a future release.The `subnet` property should be used instead.",
},
},
},
},
isFileShareTags: {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString, ValidateFunc: validate.InvokeValidator("ibm_is_share", isFileShareTags)},
Set: flex.ResourceIBMVPCHash,
Description: "User Tags for the replica share",
},
isFileShareAccessTags: {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString, ValidateFunc: validate.InvokeValidator("ibm_is_share", "accesstag")},
Set: flex.ResourceIBMVPCHash,
Description: "List of access management tags for this replica share",
},
"zone": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The name of the zone this replica file share will reside in. Must be a different zone in the same region as the source share.",
},
},
},
},
"source_share": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ConflictsWith: []string{"replica_share", "size", "source_share_crn"},
RequiredWith: []string{"replication_cron_spec"},
Description: "The ID of the source file share for this replica file share. The specified file share must not already have a replica, and must not be a replica.",
},
"source_share_crn": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ConflictsWith: []string{"replica_share", "size", "source_share"},
RequiredWith: []string{"replication_cron_spec"},
Description: "The CRN of the source file share for this replica file share. The specified file share must not already have a replica, and must not be a replica.",
},
"replication_cron_spec": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: suppressCronSpecDiff,
Computed: true,
ConflictsWith: []string{"replica_share", "size"},
Description: "The cron specification for the file share replication schedule.Replication of a share can be scheduled to occur at most once per hour.",
},
"replication_role": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The replication role of the file share.* `none`: This share is not participating in replication.* `replica`: This share is a replication target.* `source`: This share is a replication source.",
},
"replication_status": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The replication status of the file share.* `initializing`: This share is initializing replication.* `active`: This share is actively participating in replication.* `failover_pending`: This share is performing a replication failover.* `split_pending`: This share is performing a replication split.* `none`: This share is not participating in replication.* `degraded`: This share's replication sync is degraded.* `sync_pending`: This share is performing a replication sync.",
},
"replication_status_reasons": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The reasons for the current replication status (if any).The enumerated reason code values for this property will expand in the future. When processing this property, check for and log unknown values. Optionally halt processing and surface the error, or bypass the resource on which the unexpected reason code was encountered.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"code": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "A snake case string succinctly identifying the status reason.",
},
"message": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "An explanation of the status reason.",
},
"more_info": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "Link to documentation about this status reason.",
},
},
},
},
"last_sync_at": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The date and time that the file share was last synchronized to its replica.This property will be present when the `replication_role` is `source`.",
},
"latest_sync": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Information about the latest synchronization for this file share.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"completed_at": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The completed date and time of last synchronization between the replica share and its source.",
},
"data_transferred": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The data transferred (in bytes) in the last synchronization between the replica and its source.",
},
"started_at": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The start date and time of last synchronization between the replica share and its source.",
},
},
},
},
"latest_job": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The latest job associated with this file share.This property will be absent if no jobs have been created for this file share.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"status": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The status of the file share job.The enumerated values for this property will expand in the future. When processing this property, check for and log unknown values. Optionally halt processing and surface the error, or bypass the file share job on which the unexpected property value was encountered.* `cancelled`: This job has been cancelled.* `failed`: This job has failed.* `queued`: This job is queued.* `running`: This job is running.* `succeeded`: This job completed successfully.",
},
"status_reasons": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The reasons for the file share job status (if any).The enumerated reason code values for this property will expand in the future. When processing this property, check for and log unknown values. Optionally halt processing and surface the error, or bypass the resource on which the unexpected reason code was encountered.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"code": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "A snake case string succinctly identifying the status reason.",
},
"message": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "An explanation of the status reason.",
},
"more_info": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about this status reason.",
},
},
},
},
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The type of the file share job.The enumerated values for this property will expand in the future. When processing this property, check for and log unknown values. Optionally halt processing and surface the error, or bypass the file share job on which the unexpected property value was encountered.* `replication_failover`: This is a share replication failover job.* `replication_init`: This is a share replication is initialization job.* `replication_split`: This is a share replication split job.* `replication_sync`: This is a share replication synchronization job.",
},
},
},
},
"lifecycle_state": {
Type: schema.TypeString,
Computed: true,
Description: "The lifecycle state of the file share.",
},
"zone": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The globally unique name of the zone this file share will reside in.",
},
isFileShareTags: {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString, ValidateFunc: validate.InvokeValidator("ibm_is_share", isFileShareTags)},
Set: flex.ResourceIBMVPCHash,
Description: "User Tags for the file share",
},
isFileShareAccessTags: {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString, ValidateFunc: validate.InvokeValidator("ibm_is_share", "accesstag")},
Set: flex.ResourceIBMVPCHash,
Description: "List of access management tags",
},
"created_at": {
Type: schema.TypeString,
Computed: true,
Description: "The date and time that the file share is created.",
},
"crn": {
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this share.",
},
"encryption": {
Type: schema.TypeString,
Computed: true,
Description: "The type of encryption used for this file share.",
},
"href": {
Type: schema.TypeString,
Computed: true,
Description: "The URL for this share.",
},
"resource_type": {
Type: schema.TypeString,
Computed: true,
Description: "The type of resource referenced.",
},
},
}
}
func ResourceIbmIsShareValidator() *validate.ResourceValidator {
validateSchema := make([]validate.ValidateSchema, 1)
validateSchema = append(validateSchema,
validate.ValidateSchema{
Identifier: "iops",
ValidateFunctionIdentifier: validate.IntBetween,
Type: validate.TypeInt,
Optional: true,
MinValue: "100",
MaxValue: "96000",
},
validate.ValidateSchema{
Identifier: "name",
ValidateFunctionIdentifier: validate.ValidateRegexpLen,
Type: validate.TypeString,
Optional: true,
Regexp: `^([a-z]|[a-z][-a-z0-9]*[a-z0-9]|[0-9][-a-z0-9]*([a-z]|[-a-z][-a-z0-9]*[a-z0-9]))$`,
MinValueLength: 1,
MaxValueLength: 63,
},
validate.ValidateSchema{
Identifier: "size",
ValidateFunctionIdentifier: validate.IntBetween,
Type: validate.TypeInt,
Optional: true,
MinValue: "10",
MaxValue: "32000",
},
validate.ValidateSchema{
Identifier: isFileShareTags,
ValidateFunctionIdentifier: validate.ValidateRegexpLen,
Type: validate.TypeString,
Optional: true,
Regexp: `^[A-Za-z0-9:_ .-]+$`,
MinValueLength: 1,
MaxValueLength: 128,
},
validate.ValidateSchema{
Identifier: "accesstag",
ValidateFunctionIdentifier: validate.ValidateRegexpLen,
Type: validate.TypeString,
Optional: true,
Regexp: `^([A-Za-z0-9_.-]|[A-Za-z0-9_.-][A-Za-z0-9_ .-]*[A-Za-z0-9_.-]):([A-Za-z0-9_.-]|[A-Za-z0-9_.-][A-Za-z0-9_ .-]*[A-Za-z0-9_.-])$`,
MinValueLength: 1,
MaxValueLength: 128,
},
)
resourceValidator := validate.ResourceValidator{ResourceName: "ibm_is_share", Schema: validateSchema}
return &resourceValidator
}
func resourceIbmIsShareCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
vpcClient, err := meta.(conns.ClientSession).VpcV1API()
if err != nil {
return diag.FromErr(err)
}
createShareOptions := &vpcv1.CreateShareOptions{}
sharePrototype := &vpcv1.SharePrototype{}
if accessControlModeIntf, ok := d.GetOk("access_control_mode"); ok {
accessControlMode := accessControlModeIntf.(string)
sharePrototype.AccessControlMode = &accessControlMode
}
if encryptionKeyIntf, ok := d.GetOk("encryption_key"); ok {
encryptionKey := encryptionKeyIntf.(string)
encryptionKeyIdentity := &vpcv1.EncryptionKeyIdentity{
CRN: &encryptionKey,
}
sharePrototype.EncryptionKey = encryptionKeyIdentity
}
if sizeIntf, ok := d.GetOk("size"); ok {
size := int64(sizeIntf.(int))
sharePrototype.Size = &size
initial_owner := &vpcv1.ShareInitialOwner{}
if initialOwnerIntf, ok := d.GetOk("initial_owner"); ok {
initialOwnerMap := initialOwnerIntf.([]interface{})[0].(map[string]interface{})
if initialOwnerGIDIntf, ok := initialOwnerMap["gid"]; ok {
initialOwnerGID := int64(initialOwnerGIDIntf.(int))
initial_owner.Gid = &initialOwnerGID
}
if initialOwnerUIDIntf, ok := initialOwnerMap["uid"]; ok {
initialOwnerUID := int64(initialOwnerUIDIntf.(int))
initial_owner.Uid = &initialOwnerUID
}
}
if resgrp, ok := d.GetOk("resource_group"); ok {
resgrpstr := resgrp.(string)
resourceGroup := &vpcv1.ResourceGroupIdentity{
ID: &resgrpstr,
}
sharePrototype.ResourceGroup = resourceGroup
}
if replicaShareIntf, ok := d.GetOk("replica_share"); ok {
replicaShareMap := replicaShareIntf.([]interface{})[0].(map[string]interface{})
replicaShare := &vpcv1.SharePrototypeShareContext{}
iopsIntf, ok := replicaShareMap["iops"]
iops := iopsIntf.(int)
if ok && iops != 0 {
replicaShare.Iops = core.Int64Ptr(int64(iops))
}
if replicaShareMap["name"] != nil {
replicaShare.Name = core.StringPtr(replicaShareMap["name"].(string))
}
if replicaShareMap["profile"] != nil {
replicaShare.Profile = &vpcv1.ShareProfileIdentity{
Name: core.StringPtr(replicaShareMap["profile"].(string)),
}
}
if replicaShareMap["replication_cron_spec"] != nil {
replicaShare.ReplicationCronSpec = core.StringPtr(replicaShareMap["replication_cron_spec"].(string))
}
if replicaShareMap["zone"] != nil {
replicaShare.Zone = &vpcv1.ZoneIdentity{
Name: core.StringPtr(replicaShareMap["zone"].(string)),
}
}
replicaTargets, ok := replicaShareMap["mount_targets"]
if ok {
var targets []vpcv1.ShareMountTargetPrototypeIntf
targetsIntf := replicaTargets.([]interface{})
for _, targetIntf := range targetsIntf {
target := targetIntf.(map[string]interface{})
targetsItem, err := resourceIbmIsShareMapToShareMountTargetPrototype(d, target)
if err != nil {
return diag.FromErr(err)
}
targets = append(targets, &targetsItem)
}
replicaShare.MountTargets = targets
}
var userTags *schema.Set
if v, ok := replicaShareMap[isFileShareTags]; ok {
userTags = v.(*schema.Set)
if userTags != nil && userTags.Len() != 0 {
userTagsArray := make([]string, userTags.Len())
for i, userTag := range userTags.List() {
userTagStr := userTag.(string)
userTagsArray[i] = userTagStr
}
schematicTags := os.Getenv("IC_ENV_TAGS")
var envTags []string
if schematicTags != "" {
envTags = strings.Split(schematicTags, ",")
userTagsArray = append(userTagsArray, envTags...)
}
replicaShare.UserTags = userTagsArray
}
}
sharePrototype.ReplicaShare = replicaShare
}
} else {
sourceShare := d.Get("source_share").(string)
if sourceShare != "" {
sharePrototype.SourceShare = &vpcv1.ShareIdentity{
ID: &sourceShare,
}
} else {
sourceShareCRN := d.Get("source_share_crn").(string)
if sourceShareCRN != "" {
sharePrototype.SourceShare = &vpcv1.ShareIdentity{
CRN: &sourceShareCRN,
}
}
}
replicationCronSpec := d.Get("replication_cron_spec").(string)
sharePrototype.ReplicationCronSpec = &replicationCronSpec
}
if iopsIntf, ok := d.GetOk("iops"); ok {
iops := int64(iopsIntf.(int))
sharePrototype.Iops = &iops
}
if nameIntf, ok := d.GetOk("name"); ok {
name := nameIntf.(string)
sharePrototype.Name = &name
}
if profileIntf, ok := d.GetOk("profile"); ok {
profileStr := profileIntf.(string)
profile := &vpcv1.ShareProfileIdentity{
Name: &profileStr,
}
sharePrototype.Profile = profile
}
if shareTargetPrototypeIntf, ok := d.GetOk("mount_targets"); ok {
var targets []vpcv1.ShareMountTargetPrototypeIntf
for _, e := range shareTargetPrototypeIntf.([]interface{}) {
value := e.(map[string]interface{})
targetsItem, err := resourceIbmIsShareMapToShareMountTargetPrototype(d, value)
if err != nil {
return diag.FromErr(err)
}
targets = append(targets, &targetsItem)
}
sharePrototype.MountTargets = targets
}
if zone, ok := d.GetOk("zone"); ok {
zonestr := zone.(string)
zone := &vpcv1.ZoneIdentity{
Name: &zonestr,
}
sharePrototype.Zone = zone
}
var userTags *schema.Set
if v, ok := d.GetOk(isFileShareTags); ok {
userTags = v.(*schema.Set)
if userTags != nil && userTags.Len() != 0 {
userTagsArray := make([]string, userTags.Len())
for i, userTag := range userTags.List() {
userTagStr := userTag.(string)
userTagsArray[i] = userTagStr
}
schematicTags := os.Getenv("IC_ENV_TAGS")
var envTags []string
if schematicTags != "" {
envTags = strings.Split(schematicTags, ",")
userTagsArray = append(userTagsArray, envTags...)
}
sharePrototype.UserTags = userTagsArray
}
}
createShareOptions.SetSharePrototype(sharePrototype)
share, response, err := vpcClient.CreateShareWithContext(context, createShareOptions)
if err != nil {
log.Printf("[DEBUG] CreateShareWithContext failed %s\n%s", err, response)
return diag.FromErr(err)
}
_, err = isWaitForShareAvailable(context, vpcClient, *share.ID, d, d.Timeout(schema.TimeoutCreate))
if err != nil {
return diag.FromErr(err)
}
if share.ReplicaShare != nil && share.ReplicaShare.ID != nil {
_, err = isWaitForShareAvailable(context, vpcClient, *share.ReplicaShare.ID, d, d.Timeout(schema.TimeoutCreate))
if err != nil {
return diag.FromErr(err)
}
replicaShareAccessTagsSchema := "replica_share.0.access_tags"
if _, ok := d.GetOk(replicaShareAccessTagsSchema); ok {
oldList, newList := d.GetChange(replicaShareAccessTagsSchema)
err = flex.UpdateGlobalTagsUsingCRN(oldList, newList, meta, *share.ReplicaShare.CRN, "", isAccessTagType)
if err != nil {
log.Printf(
"Error creating replica file share (%s) access tags: %s", d.Id(), err)
}
}
}
d.SetId(*share.ID)
if _, ok := d.GetOk(isFileShareAccessTags); ok {
oldList, newList := d.GetChange(isFileShareAccessTags)
err = flex.UpdateGlobalTagsUsingCRN(oldList, newList, meta, *share.CRN, "", isAccessTagType)
if err != nil {
log.Printf(
"Error creating file share (%s) access tags: %s", d.Id(), err)
}
}
return resourceIbmIsShareRead(context, d, meta)
}
func resourceIbmIsShareMapToShareMountTargetPrototype(d *schema.ResourceData, shareTargetPrototypeMap map[string]interface{}) (vpcv1.ShareMountTargetPrototype, error) {
shareTargetPrototype := vpcv1.ShareMountTargetPrototype{}
if nameIntf, ok := shareTargetPrototypeMap["name"]; ok && nameIntf != "" {
shareTargetPrototype.Name = core.StringPtr(nameIntf.(string))
}
if vpcIntf, ok := shareTargetPrototypeMap["vpc"]; ok && vpcIntf != "" {
vpc := vpcIntf.(string)
shareTargetPrototype.VPC = &vpcv1.VPCIdentity{
ID: &vpc,
}
} else if vniIntf, ok := shareTargetPrototypeMap["virtual_network_interface"]; ok {
vniPrototype := vpcv1.ShareMountTargetVirtualNetworkInterfacePrototype{}
vniMap := vniIntf.([]interface{})[0].(map[string]interface{})
vniPrototype, err := ShareMountTargetMapToShareMountTargetPrototype(d, vniMap)
if err != nil {
return shareTargetPrototype, err
}
shareTargetPrototype.VirtualNetworkInterface = &vniPrototype
}
if transitEncryptionIntf, ok := shareTargetPrototypeMap["transit_encryption"]; ok && transitEncryptionIntf != "" {
transitEncryption := transitEncryptionIntf.(string)
shareTargetPrototype.TransitEncryption = &transitEncryption
}
return shareTargetPrototype, nil
}
func resourceIbmIsShareRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
vpcClient, err := meta.(conns.ClientSession).VpcV1API()
if err != nil {
return diag.FromErr(err)
}
getShareOptions := &vpcv1.GetShareOptions{}