-
Notifications
You must be signed in to change notification settings - Fork 669
/
data_source_ibm_is_volumes.go
978 lines (905 loc) · 38.3 KB
/
data_source_ibm_is_volumes.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
// Copyright IBM Corp. 2021 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package vpc
import (
"context"
"fmt"
"log"
"time"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/IBM/vpc-go-sdk/vpcv1"
)
const (
isVolumes = "volumes"
isVolumesActive = "active"
isVolumesBandwidth = "bandwidth"
isVolumesBusy = "busy"
isVolumesCapacity = "capacity"
isVolumesCreatedAt = "created_at"
isVolumesCRN = "crn"
isVolumesEncryption = "encryption"
isVolumesEncryptionKey = "encryption_key"
isVolumesEncryptionKeyCRN = "crn"
isVolumesHref = "href"
isVolumesId = "id"
isVolumesIops = "iops"
isVolumesName = "name"
isVolumesOperatingSystem = "operating_system"
isVolumesOperatingSystemHref = "href"
isVolumesOperatingSystemName = "name"
isVolumesProfile = "profile"
isVolumesProfileHref = "href"
isVolumesProfileName = "name"
isVolumesResourceGroup = "resource_group"
isVolumesResourceGroupHref = "href"
isVolumesResourceGroupId = "id"
isVolumesResourceGroupName = "name"
isVolumesSourceImage = "source_image"
isVolumesSourceImageCRN = "crn"
isVolumesSourceImageDeleted = "deleted"
isVolumesSourceImageDeletedMoreInfo = "more_info"
isVolumesSourceImageHref = "href"
isVolumesSourceImageId = "id"
isVolumesSourceImageName = "name"
isVolumesSourceSnapshot = "source_snapshot"
isVolumesSourceSnapshotCRN = "crn"
isVolumesSourceSnapshotDeleted = "deleted"
isVolumesSourceSnapshotDeletedMoreInfo = "more_info"
isVolumesSourceSnapshotHref = "href"
isVolumesSourceSnapshotId = "id"
isVolumesSourceSnapshotName = "name"
isVolumesSourceSnapshotResourceType = "resource_type"
isVolumesStatus = "status"
isVolumesStatusReasons = "status_reasons"
isVolumesStatusReasonsCode = "code"
isVolumesStatusReasonsMessage = "message"
isVolumesStatusReasonsMoreInfo = "more_info"
isVolumesVolumeAttachments = "volume_attachments"
isVolumesVolumeAttachmentsDeleteVolumeOnInstanceDelete = "delete_volume_on_instance_delete"
isVolumesVolumeAttachmentsDeleted = "deleted"
isVolumesVolumeAttachmentsDeletedMoreInfo = "more_info"
isVolumesVolumeAttachmentsDevice = "device"
isVolumesVolumeAttachmentsDeviceId = "id"
isVolumesVolumeAttachmentsHref = "href"
isVolumesVolumeAttachmentsId = "id"
isVolumesVolumeAttachmentsInstance = "instance"
isVolumesVolumeAttachmentsInstanceCRN = "crn"
isVolumesVolumeAttachmentsInstanceDeleted = "deleted"
isVolumesVolumeAttachmentsInstanceDeletedMoreInfo = "more_info"
isVolumesVolumeAttachmentsInstanceHref = "href"
isVolumesVolumeAttachmentsInstanceId = "id"
isVolumesVolumeAttachmentsInstanceName = "name"
isVolumesVolumeAttachmentsName = "name"
isVolumesVolumeAttachmentsType = "type"
isVolumesZone = "zone"
isVolumesZoneHref = "href"
isVolumesZoneName = "name"
)
func DataSourceIBMIsVolumes() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceIBMIsVolumesRead,
Schema: map[string]*schema.Schema{
"volume_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "Volume name identifier.",
},
"zone_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "Zone name identifier.",
},
isVolumes: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Collection of volumes.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
isVolumesActive: &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether a running virtual server instance has an attachment to this volume.",
},
isVolumesBandwidth: &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The maximum bandwidth (in megabits per second) for the volume.",
},
isVolumesBusy: &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether this volume is performing an operation that must be serialized. If an operation specifies that it requires serialization, the operation will fail unless this property is `false`.",
},
isVolumesCapacity: &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The capacity to use for the volume (in gigabytes). The specified minimum and maximum capacity values for creating or updating volumes may expand in the future.",
},
isVolumesCreatedAt: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The date and time that the volume was created.",
},
isVolumesCRN: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this volume.",
},
isVolumesEncryption: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The type of encryption used on the volume.",
},
isVolumesEncryptionKey: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The root key used to wrap the data encryption key for the volume.This property will be present for volumes with an `encryption` type of`user_managed`.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
isVolumesEncryptionKeyCRN: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN of the [Key Protect Root Key](https://cloud.ibm.com/docs/key-protect?topic=key-protect-getting-started-tutorial) or [Hyper Protect Crypto Service Root Key](https://cloud.ibm.com/docs/hs-crypto?topic=hs-crypto-get-started) for this resource.",
},
},
},
},
isVolumesHref: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this volume.",
},
isVolumesId: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this volume.",
},
isVolumesIops: &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The maximum I/O operations per second (IOPS) to use for the volume. Applicable only to volumes using a profile `family` of `custom`.",
},
isVolumesName: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique user-defined name for this volume.",
},
isVolumesOperatingSystem: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The operating system associated with this volume. If absent, this volume was notcreated from an image, or the image did not include an operating system.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
isVolumesOperatingSystemHref: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this operating system.",
},
isVolumesOperatingSystemName: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The globally unique name for this operating system.",
},
},
},
},
isVolumesProfile: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The profile this volume uses.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
isVolumesProfileHref: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this volume profile.",
},
isVolumesProfileName: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The globally unique name for this volume profile.",
},
},
},
},
isVolumesResourceGroup: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The resource group for this volume.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
isVolumesResourceGroupHref: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this resource group.",
},
isVolumesResourceGroupId: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this resource group.",
},
isVolumesResourceGroupName: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The user-defined name for this resource group.",
},
},
},
},
isVolumesSourceImage: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The image from which this volume was created (this may be[deleted](https://cloud.ibm.com/apidocs/vpc#deleted-resources)).If absent, this volume was not created from an image.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
isVolumesSourceImageCRN: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this image.",
},
isVolumesSourceImageDeleted: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "If present, this property indicates the referenced resource has been deleted and providessome supplementary information.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
isVolumesSourceImageDeletedMoreInfo: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about deleted resources.",
},
},
},
},
isVolumesSourceImageHref: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this image.",
},
isVolumesSourceImageId: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this image.",
},
isVolumesSourceImageName: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The user-defined or system-provided name for this image.",
},
},
},
},
isVolumesSourceSnapshot: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The snapshot from which this volume was cloned.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
isVolumesSourceSnapshotCRN: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this snapshot.",
},
isVolumesSourceSnapshotDeleted: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "If present, this property indicates the referenced resource has been deleted and providessome supplementary information.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
isVolumesSourceSnapshotDeletedMoreInfo: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about deleted resources.",
},
},
},
},
isVolumesSourceSnapshotHref: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this snapshot.",
},
isVolumesSourceSnapshotId: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this snapshot.",
},
isVolumesSourceSnapshotName: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The user-defined name for this snapshot.",
},
isVolumesSourceSnapshotResourceType: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The resource type.",
},
},
},
},
isVolumesStatus: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The status of the volume.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 volume on which the unexpected property value was encountered.",
},
isVolumesStatusReasons: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The reasons for the current 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{
isVolumesStatusReasonsCode: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "A snake case string succinctly identifying the status reason.",
},
isVolumesStatusReasonsMessage: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "An explanation of the status reason.",
},
isVolumesStatusReasonsMoreInfo: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about this status reason.",
},
},
},
},
isVolumesVolumeAttachments: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The volume attachments for this volume.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
isVolumesVolumeAttachmentsDeleteVolumeOnInstanceDelete: &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "If set to true, when deleting the instance the volume will also be deleted.",
},
isVolumesVolumeAttachmentsDeleted: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "If present, this property indicates the referenced resource has been deleted and providessome supplementary information.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
isVolumesVolumeAttachmentsDeletedMoreInfo: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about deleted resources.",
},
},
},
},
isVolumesVolumeAttachmentsDevice: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Information about how the volume is exposed to the instance operating system.This property may be absent if the volume attachment's `status` is not `attached`.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
isVolumesVolumeAttachmentsDeviceId: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "A unique identifier for the device which is exposed to the instance operating system.",
},
},
},
},
isVolumesVolumeAttachmentsHref: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this volume attachment.",
},
isVolumesVolumeAttachmentsId: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this volume attachment.",
},
isVolumesVolumeAttachmentsInstance: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The attached instance.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
isVolumesVolumeAttachmentsInstanceCRN: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this virtual server instance.",
},
isVolumesVolumeAttachmentsInstanceDeleted: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "If present, this property indicates the referenced resource has been deleted and providessome supplementary information.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
isVolumesVolumeAttachmentsInstanceDeletedMoreInfo: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about deleted resources.",
},
},
},
},
isVolumesVolumeAttachmentsInstanceHref: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this virtual server instance.",
},
isVolumesVolumeAttachmentsInstanceId: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this virtual server instance.",
},
isVolumesVolumeAttachmentsInstanceName: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The user-defined name for this virtual server instance (and default system hostname).",
},
},
},
},
isVolumesVolumeAttachmentsName: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The user-defined name for this volume attachment.",
},
isVolumesVolumeAttachmentsType: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The type of volume attachment.",
},
},
},
},
isVolumesZone: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The zone this volume resides in.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
isVolumesZoneHref: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this zone.",
},
isVolumesZoneName: &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The globally unique name for this zone.",
},
},
},
},
isVolumeTags: {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: flex.ResourceIBMVPCHash,
Description: "User Tags for the Volume",
},
isVolumeAccessTags: {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: flex.ResourceIBMVPCHash,
Description: "Access management tags for the volume instance",
},
isVolumeHealthReasons: {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
isVolumeHealthReasonsCode: {
Type: schema.TypeString,
Computed: true,
Description: "A snake case string succinctly identifying the reason for this health state.",
},
isVolumeHealthReasonsMessage: {
Type: schema.TypeString,
Computed: true,
Description: "An explanation of the reason for this health state.",
},
isVolumeHealthReasonsMoreInfo: {
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about the reason for this health state.",
},
},
},
},
isVolumeHealthState: {
Type: schema.TypeString,
Computed: true,
Description: "The health of this resource.",
},
},
},
},
},
}
}
func dataSourceIBMIsVolumesRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
vpcClient, err := meta.(conns.ClientSession).VpcV1API()
if err != nil {
return diag.FromErr(err)
}
// filters - volume-name and zone-name
volumeName := d.Get("volume_name").(string)
zoneName := d.Get("zone_name").(string)
start := ""
allrecs := []vpcv1.Volume{}
// list
for {
listVolumesOptions := &vpcv1.ListVolumesOptions{}
if start != "" {
listVolumesOptions.Start = &start
}
if volumeName != "" {
listVolumesOptions.Name = &volumeName
}
if zoneName != "" {
listVolumesOptions.ZoneName = &zoneName
}
volumeCollection, response, err := vpcClient.ListVolumesWithContext(context, listVolumesOptions)
if err != nil {
log.Printf("[DEBUG] ListVolumesWithContext failed %s\n%s", err, response)
return diag.FromErr(fmt.Errorf("ListVolumesWithContext failed %s\n%s", err, response))
}
start = flex.GetNext(volumeCollection.Next)
allrecs = append(allrecs, volumeCollection.Volumes...)
if start == "" {
break
}
}
d.SetId(dataSourceIBMIsVolumesID(d))
err = d.Set(isVolumes, dataSourceVolumeCollectionFlattenVolumes(allrecs, meta))
if err != nil {
return diag.FromErr(fmt.Errorf("Error setting volumes %s", err))
}
return nil
}
// dataSourceIBMIsVolumesID returns a reasonable ID for the list.
func dataSourceIBMIsVolumesID(d *schema.ResourceData) string {
return time.Now().UTC().String()
}
func dataSourceVolumeCollectionFlattenVolumes(result []vpcv1.Volume, meta interface{}) (volumes []map[string]interface{}) {
for _, volumesItem := range result {
volumes = append(volumes, dataSourceVolumeCollectionVolumesToMap(volumesItem, meta))
}
return volumes
}
func dataSourceVolumeCollectionVolumesToMap(volumesItem vpcv1.Volume, meta interface{}) (volumesMap map[string]interface{}) {
volumesMap = map[string]interface{}{}
if volumesItem.Active != nil {
volumesMap[isVolumesActive] = volumesItem.Active
}
if volumesItem.Bandwidth != nil {
volumesMap[isVolumesBandwidth] = volumesItem.Bandwidth
}
if volumesItem.Busy != nil {
volumesMap[isVolumesBusy] = volumesItem.Busy
}
if volumesItem.Capacity != nil {
volumesMap[isVolumesCapacity] = volumesItem.Capacity
}
if volumesItem.CreatedAt != nil {
volumesMap[isVolumesCreatedAt] = volumesItem.CreatedAt.String()
}
if volumesItem.CRN != nil {
volumesMap[isVolumesCRN] = volumesItem.CRN
}
if volumesItem.Encryption != nil {
volumesMap[isVolumesEncryption] = volumesItem.Encryption
}
if volumesItem.EncryptionKey != nil {
encryptionKeyList := []map[string]interface{}{}
encryptionKeyMap := dataSourceVolumeCollectionVolumesEncryptionKeyToMap(*volumesItem.EncryptionKey)
encryptionKeyList = append(encryptionKeyList, encryptionKeyMap)
volumesMap[isVolumesEncryptionKey] = encryptionKeyList
}
if volumesItem.Href != nil {
volumesMap[isVolumesHref] = volumesItem.Href
}
if volumesItem.ID != nil {
volumesMap[isVolumesId] = volumesItem.ID
}
if volumesItem.Iops != nil {
volumesMap[isVolumesIops] = volumesItem.Iops
}
if volumesItem.Name != nil {
volumesMap[isVolumesName] = volumesItem.Name
}
if volumesItem.OperatingSystem != nil {
operatingSystemList := []map[string]interface{}{}
operatingSystemMap := dataSourceVolumeCollectionVolumesOperatingSystemToMap(*volumesItem.OperatingSystem)
operatingSystemList = append(operatingSystemList, operatingSystemMap)
volumesMap[isVolumesOperatingSystem] = operatingSystemList
}
if volumesItem.Profile != nil {
profileList := []map[string]interface{}{}
profileMap := dataSourceVolumeCollectionVolumesProfileToMap(*volumesItem.Profile)
profileList = append(profileList, profileMap)
volumesMap[isVolumesProfile] = profileList
}
if volumesItem.ResourceGroup != nil {
resourceGroupList := []map[string]interface{}{}
resourceGroupMap := dataSourceVolumeCollectionVolumesResourceGroupToMap(*volumesItem.ResourceGroup)
resourceGroupList = append(resourceGroupList, resourceGroupMap)
volumesMap[isVolumesResourceGroup] = resourceGroupList
}
if volumesItem.SourceImage != nil {
sourceImageList := []map[string]interface{}{}
sourceImageMap := dataSourceVolumeCollectionVolumesSourceImageToMap(*volumesItem.SourceImage)
sourceImageList = append(sourceImageList, sourceImageMap)
volumesMap[isVolumesSourceImage] = sourceImageList
}
if volumesItem.SourceSnapshot != nil {
sourceSnapshotList := []map[string]interface{}{}
sourceSnapshotMap := dataSourceVolumeCollectionVolumesSourceSnapshotToMap(*volumesItem.SourceSnapshot)
sourceSnapshotList = append(sourceSnapshotList, sourceSnapshotMap)
volumesMap[isVolumesSourceSnapshot] = sourceSnapshotList
}
if volumesItem.Status != nil {
volumesMap[isVolumesStatus] = volumesItem.Status
}
if volumesItem.HealthState != nil {
volumesMap[isVolumeHealthState] = volumesItem.HealthState
}
if volumesItem.StatusReasons != nil {
statusReasonsList := []map[string]interface{}{}
for _, statusReasonsItem := range volumesItem.StatusReasons {
statusReasonsList = append(statusReasonsList, dataSourceVolumeCollectionVolumesStatusReasonsToMap(statusReasonsItem))
}
volumesMap[isVolumesStatusReasons] = statusReasonsList
}
if volumesItem.HealthReasons != nil {
healthReasonsList := []map[string]interface{}{}
for _, healthReasonsItem := range volumesItem.HealthReasons {
healthReasonsList = append(healthReasonsList, dataSourceVolumeCollectionVolumesHealthReasonsToMap(healthReasonsItem))
}
volumesMap[isVolumeHealthReasons] = healthReasonsList
}
if volumesItem.VolumeAttachments != nil {
volumeAttachmentsList := []map[string]interface{}{}
for _, volumeAttachmentsItem := range volumesItem.VolumeAttachments {
volumeAttachmentsList = append(volumeAttachmentsList, dataSourceVolumeCollectionVolumesVolumeAttachmentsToMap(volumeAttachmentsItem))
}
volumesMap[isVolumesVolumeAttachments] = volumeAttachmentsList
}
if volumesItem.Zone != nil {
zoneList := []map[string]interface{}{}
zoneMap := dataSourceVolumeCollectionVolumesZoneToMap(*volumesItem.Zone)
zoneList = append(zoneList, zoneMap)
volumesMap[isVolumesZone] = zoneList
}
if volumesItem.UserTags != nil {
volumesMap[isVolumeTags] = volumesItem.UserTags
}
accesstags, err := flex.GetGlobalTagsUsingCRN(meta, *volumesItem.CRN, "", isVolumeAccessTagType)
if err != nil {
log.Printf(
"Error on get of resource vpc volume (%s) access tags: %s", *volumesItem.ID, err)
}
volumesMap[isVolumeAccessTags] = accesstags
return volumesMap
}
func dataSourceVolumeCollectionVolumesEncryptionKeyToMap(encryptionKeyItem vpcv1.EncryptionKeyReference) (encryptionKeyMap map[string]interface{}) {
encryptionKeyMap = map[string]interface{}{}
if encryptionKeyItem.CRN != nil {
encryptionKeyMap[isVolumesEncryptionKeyCRN] = encryptionKeyItem.CRN
}
return encryptionKeyMap
}
func dataSourceVolumeCollectionVolumesOperatingSystemToMap(operatingSystemItem vpcv1.OperatingSystemReference) (operatingSystemMap map[string]interface{}) {
operatingSystemMap = map[string]interface{}{}
if operatingSystemItem.Href != nil {
operatingSystemMap[isVolumesOperatingSystemHref] = operatingSystemItem.Href
}
if operatingSystemItem.Name != nil {
operatingSystemMap[isVolumesOperatingSystemName] = operatingSystemItem.Name
}
return operatingSystemMap
}
func dataSourceVolumeCollectionVolumesProfileToMap(profileItem vpcv1.VolumeProfileReference) (profileMap map[string]interface{}) {
profileMap = map[string]interface{}{}
if profileItem.Href != nil {
profileMap[isVolumesProfileHref] = profileItem.Href
}
if profileItem.Name != nil {
profileMap[isVolumesProfileName] = profileItem.Name
}
return profileMap
}
func dataSourceVolumeCollectionVolumesResourceGroupToMap(resourceGroupItem vpcv1.ResourceGroupReference) (resourceGroupMap map[string]interface{}) {
resourceGroupMap = map[string]interface{}{}
if resourceGroupItem.Href != nil {
resourceGroupMap[isVolumesResourceGroupHref] = resourceGroupItem.Href
}
if resourceGroupItem.ID != nil {
resourceGroupMap[isVolumesResourceGroupId] = resourceGroupItem.ID
}
if resourceGroupItem.Name != nil {
resourceGroupMap[isVolumesResourceGroupName] = resourceGroupItem.Name
}
return resourceGroupMap
}
func dataSourceVolumeCollectionVolumesSourceImageToMap(sourceImageItem vpcv1.ImageReference) (sourceImageMap map[string]interface{}) {
sourceImageMap = map[string]interface{}{}
if sourceImageItem.CRN != nil {
sourceImageMap[isVolumesSourceImageCRN] = sourceImageItem.CRN
}
if sourceImageItem.Deleted != nil {
deletedList := []map[string]interface{}{}
deletedMap := dataSourceVolumeCollectionSourceImageDeletedToMap(*sourceImageItem.Deleted)
deletedList = append(deletedList, deletedMap)
sourceImageMap[isVolumesSourceImageDeleted] = deletedList
}
if sourceImageItem.Href != nil {
sourceImageMap[isVolumesSourceImageHref] = sourceImageItem.Href
}
if sourceImageItem.ID != nil {
sourceImageMap[isVolumesSourceImageId] = sourceImageItem.ID
}
if sourceImageItem.Name != nil {
sourceImageMap[isVolumesSourceImageName] = sourceImageItem.Name
}
return sourceImageMap
}
func dataSourceVolumeCollectionSourceImageDeletedToMap(deletedItem vpcv1.ImageReferenceDeleted) (deletedMap map[string]interface{}) {
deletedMap = map[string]interface{}{}
if deletedItem.MoreInfo != nil {
deletedMap[isVolumesSourceImageDeletedMoreInfo] = deletedItem.MoreInfo
}
return deletedMap
}
func dataSourceVolumeCollectionVolumesSourceSnapshotToMap(sourceSnapshotItem vpcv1.SnapshotReference) (sourceSnapshotMap map[string]interface{}) {
sourceSnapshotMap = map[string]interface{}{}
if sourceSnapshotItem.CRN != nil {
sourceSnapshotMap[isVolumesSourceSnapshotCRN] = sourceSnapshotItem.CRN
}
if sourceSnapshotItem.Deleted != nil {
deletedList := []map[string]interface{}{}
deletedMap := dataSourceVolumeCollectionSourceSnapshotDeletedToMap(*sourceSnapshotItem.Deleted)
deletedList = append(deletedList, deletedMap)
sourceSnapshotMap[isVolumesSourceSnapshotDeleted] = deletedList
}
if sourceSnapshotItem.Href != nil {
sourceSnapshotMap[isVolumesSourceSnapshotHref] = sourceSnapshotItem.Href
}
if sourceSnapshotItem.ID != nil {
sourceSnapshotMap[isVolumesSourceSnapshotId] = sourceSnapshotItem.ID
}
if sourceSnapshotItem.Name != nil {
sourceSnapshotMap[isVolumesSourceSnapshotName] = sourceSnapshotItem.Name
}
if sourceSnapshotItem.ResourceType != nil {
sourceSnapshotMap[isVolumesSourceSnapshotResourceType] = sourceSnapshotItem.ResourceType
}
return sourceSnapshotMap
}
func dataSourceVolumeCollectionSourceSnapshotDeletedToMap(deletedItem vpcv1.SnapshotReferenceDeleted) (deletedMap map[string]interface{}) {
deletedMap = map[string]interface{}{}
if deletedItem.MoreInfo != nil {
deletedMap[isVolumesSourceSnapshotDeletedMoreInfo] = deletedItem.MoreInfo
}
return deletedMap
}
func dataSourceVolumeCollectionVolumesStatusReasonsToMap(statusReasonsItem vpcv1.VolumeStatusReason) (statusReasonsMap map[string]interface{}) {
statusReasonsMap = map[string]interface{}{}
if statusReasonsItem.Code != nil {
statusReasonsMap[isVolumesStatusReasonsCode] = statusReasonsItem.Code
}
if statusReasonsItem.Message != nil {
statusReasonsMap[isVolumesStatusReasonsMessage] = statusReasonsItem.Message
}
if statusReasonsItem.MoreInfo != nil {
statusReasonsMap[isVolumesStatusReasonsMoreInfo] = statusReasonsItem.MoreInfo
}
return statusReasonsMap
}
func dataSourceVolumeCollectionVolumesHealthReasonsToMap(statusReasonsItem vpcv1.VolumeHealthReason) (healthReasonsMap map[string]interface{}) {
healthReasonsMap = map[string]interface{}{}
if statusReasonsItem.Code != nil {
healthReasonsMap[isVolumeHealthReasonsCode] = statusReasonsItem.Code
}
if statusReasonsItem.Message != nil {
healthReasonsMap[isVolumeHealthReasonsMessage] = statusReasonsItem.Message
}
if statusReasonsItem.MoreInfo != nil {
healthReasonsMap[isVolumeHealthReasonsMoreInfo] = statusReasonsItem.MoreInfo
}
return healthReasonsMap
}
func dataSourceVolumeCollectionVolumesVolumeAttachmentsToMap(volumeAttachmentsItem vpcv1.VolumeAttachmentReferenceVolumeContext) (volumeAttachmentsMap map[string]interface{}) {
volumeAttachmentsMap = map[string]interface{}{}
if volumeAttachmentsItem.DeleteVolumeOnInstanceDelete != nil {
volumeAttachmentsMap[isVolumesVolumeAttachmentsDeleteVolumeOnInstanceDelete] = volumeAttachmentsItem.DeleteVolumeOnInstanceDelete
}
if volumeAttachmentsItem.Deleted != nil {
deletedList := []map[string]interface{}{}
deletedMap := dataSourceVolumeCollectionVolumeAttachmentsDeletedToMap(*volumeAttachmentsItem.Deleted)
deletedList = append(deletedList, deletedMap)
volumeAttachmentsMap[isVolumesVolumeAttachmentsDeleted] = deletedList
}
if volumeAttachmentsItem.Device != nil {
deviceList := []map[string]interface{}{}
deviceMap := dataSourceVolumeCollectionVolumeAttachmentsDeviceToMap(*volumeAttachmentsItem.Device)
deviceList = append(deviceList, deviceMap)
volumeAttachmentsMap[isVolumesVolumeAttachmentsDevice] = deviceList
}
if volumeAttachmentsItem.Href != nil {
volumeAttachmentsMap[isVolumesVolumeAttachmentsHref] = volumeAttachmentsItem.Href
}
if volumeAttachmentsItem.ID != nil {
volumeAttachmentsMap[isVolumesVolumeAttachmentsId] = volumeAttachmentsItem.ID
}
if volumeAttachmentsItem.Instance != nil {
instanceList := []map[string]interface{}{}
instanceMap := dataSourceVolumeCollectionVolumeAttachmentsInstanceToMap(*volumeAttachmentsItem.Instance)
instanceList = append(instanceList, instanceMap)
volumeAttachmentsMap[isVolumesVolumeAttachmentsInstance] = instanceList
}
if volumeAttachmentsItem.Name != nil {
volumeAttachmentsMap[isVolumesVolumeAttachmentsName] = volumeAttachmentsItem.Name
}
if volumeAttachmentsItem.Type != nil {
volumeAttachmentsMap[isVolumesVolumeAttachmentsType] = volumeAttachmentsItem.Type
}
return volumeAttachmentsMap
}
func dataSourceVolumeCollectionVolumeAttachmentsDeletedToMap(deletedItem vpcv1.VolumeAttachmentReferenceVolumeContextDeleted) (deletedMap map[string]interface{}) {
deletedMap = map[string]interface{}{}
if deletedItem.MoreInfo != nil {
deletedMap[isVolumesVolumeAttachmentsDeletedMoreInfo] = deletedItem.MoreInfo
}
return deletedMap
}
func dataSourceVolumeCollectionVolumeAttachmentsDeviceToMap(deviceItem vpcv1.VolumeAttachmentDevice) (deviceMap map[string]interface{}) {
deviceMap = map[string]interface{}{}
if deviceItem.ID != nil {
deviceMap[isVolumesVolumeAttachmentsDeviceId] = deviceItem.ID
}
return deviceMap
}
func dataSourceVolumeCollectionVolumeAttachmentsInstanceToMap(instanceItem vpcv1.InstanceReference) (instanceMap map[string]interface{}) {
instanceMap = map[string]interface{}{}
if instanceItem.CRN != nil {
instanceMap[isVolumesVolumeAttachmentsInstanceCRN] = instanceItem.CRN
}
if instanceItem.Deleted != nil {
deletedList := []map[string]interface{}{}
deletedMap := dataSourceVolumeCollectionInstanceDeletedToMap(*instanceItem.Deleted)
deletedList = append(deletedList, deletedMap)
instanceMap[isVolumesVolumeAttachmentsInstanceDeleted] = deletedList
}
if instanceItem.Href != nil {
instanceMap[isVolumesVolumeAttachmentsInstanceHref] = instanceItem.Href
}
if instanceItem.ID != nil {
instanceMap[isVolumesVolumeAttachmentsInstanceId] = instanceItem.ID
}
if instanceItem.Name != nil {
instanceMap[isVolumesVolumeAttachmentsInstanceName] = instanceItem.Name
}
return instanceMap
}
func dataSourceVolumeCollectionInstanceDeletedToMap(deletedItem vpcv1.InstanceReferenceDeleted) (deletedMap map[string]interface{}) {
deletedMap = map[string]interface{}{}
if deletedItem.MoreInfo != nil {
deletedMap[isVolumesVolumeAttachmentsInstanceDeletedMoreInfo] = deletedItem.MoreInfo
}
return deletedMap
}
func dataSourceVolumeCollectionVolumesZoneToMap(zoneItem vpcv1.ZoneReference) (zoneMap map[string]interface{}) {
zoneMap = map[string]interface{}{}
if zoneItem.Href != nil {
zoneMap[isVolumesZoneHref] = zoneItem.Href
}
if zoneItem.Name != nil {
zoneMap[isVolumesZoneName] = zoneItem.Name
}
return zoneMap
}