-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathresource_volume.go
866 lines (763 loc) · 24.1 KB
/
resource_volume.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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package nomad
import (
"bytes"
"context"
"errors"
"fmt"
"hash/crc32"
"log"
"strings"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func resourceVolume() *schema.Resource {
return &schema.Resource{
DeprecationMessage: "nomad_volume is deprecated and may be removed in a future release. Use nomad_csi_volume_registration instead.",
Create: resourceVolumeCreate,
Update: resourceVolumeCreate,
Delete: resourceVolumeDelete,
Read: resourceVolumeRead,
Schema: map[string]*schema.Schema{
// the following cannot be updated without destroying:
// - Namespace/ID
// - PluginID
// - ExternalID
// - Type
"type": {
ForceNew: true,
Type: schema.TypeString,
Optional: true,
Description: "The type of the volume. Currently, only 'csi' is supported.",
Default: "csi",
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"csi"}, false),
},
},
"namespace": {
ForceNew: true,
Description: "The namespace in which to create the volume.",
Optional: true,
Default: "default",
Type: schema.TypeString,
},
"volume_id": {
ForceNew: true,
Description: "The unique ID of the volume, how jobs will refer to the volume.",
Required: true,
Type: schema.TypeString,
},
"name": {
Description: "The display name of the volume.",
Required: true,
Type: schema.TypeString,
},
"plugin_id": {
ForceNew: true,
Description: "The ID of the CSI plugin that manages this volume.",
Required: true,
Type: schema.TypeString,
},
"external_id": {
ForceNew: true,
Description: "The ID of the physical volume from the storage provider.",
Required: true,
Type: schema.TypeString,
},
"capability": {
Description: "Capabilities intended to be used in a job. At least one capability must be provided.",
// COMPAT(1.5.0)
// Update once `access_mode` and `attachment_mode` are removed.
ForceNew: false,
Optional: true,
ConflictsWith: []string{"access_mode", "attachment_mode"},
Type: schema.TypeSet,
MinItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"access_mode": {
Description: "Defines whether a volume should be available concurrently.",
Type: schema.TypeString,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
"single-node-reader-only",
"single-node-writer",
"multi-node-reader-only",
"multi-node-single-writer",
"multi-node-multi-writer",
}, false),
},
},
"attachment_mode": {
Description: "The storage API that will be used by the volume.",
Required: true,
Type: schema.TypeString,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
"block-device",
"file-system",
}, false),
},
},
},
},
Set: func(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%s-", m["access_mode"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["attachment_mode"].(string)))
i := int(crc32.ChecksumIEEE(buf.Bytes()))
if i >= 0 {
return i
}
if -i >= 0 {
return -i
}
// i == MinInt
return 0
},
},
"mount_options": {
Description: "Options for mounting 'block-device' volumes without a pre-formatted file system.",
Optional: true,
Type: schema.TypeList,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"fs_type": {
Description: "The file system type.",
Type: schema.TypeString,
Optional: true,
},
"mount_flags": {
Description: "The flags passed to mount.",
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
},
},
},
},
"secrets": {
Description: "An optional key-value map of strings used as credentials for publishing and unpublishing volumes.",
Optional: true,
Type: schema.TypeMap,
Sensitive: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"parameters": {
Description: "An optional key-value map of strings passed directly to the CSI plugin to configure the volume.",
Optional: true,
Type: schema.TypeMap,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"topology_request": {
ForceNew: true,
Description: "Specify locations (region, zone, rack, etc.) where the provisioned volume is accessible from.",
Optional: true,
Type: schema.TypeList,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"required": {
ForceNew: true,
Description: "Required topologies indicate that the volume must be created in a location accessible from all the listed topologies.",
Optional: true,
Type: schema.TypeList,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"topology": {
ForceNew: true,
Description: "Defines the location for the volume.",
Required: true,
Type: schema.TypeList,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"segments": {
ForceNew: true,
Description: "Define attributes for the topology request.",
Required: true,
Type: schema.TypeMap,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
},
},
},
// Volume registration does not support preferred topologies.
// https://www.nomadproject.io/docs/commands/volume/register#topology_request-parameters
},
},
},
"context": {
Description: "An optional key-value map of strings passed directly to the CSI plugin to validate the volume.",
Optional: true,
Type: schema.TypeMap,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"deregister_on_destroy": {
Description: "If true, the volume will be deregistered on destroy.",
Optional: true,
Default: true,
Type: schema.TypeBool,
},
"controller_required": {
Computed: true,
Type: schema.TypeBool,
},
"controllers_expected": {
Computed: true,
Type: schema.TypeInt,
},
"controllers_healthy": {
Computed: true,
Type: schema.TypeInt,
},
"plugin_provider": {
Computed: true,
Type: schema.TypeString,
},
"plugin_provider_version": {
Computed: true,
Type: schema.TypeString,
},
"nodes_healthy": {
Computed: true,
Type: schema.TypeInt,
},
"nodes_expected": {
Computed: true,
Type: schema.TypeInt,
},
"schedulable": {
Computed: true,
Type: schema.TypeBool,
},
"topologies": {
Computed: true,
Type: schema.TypeList,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"segments": {
Computed: true,
Type: schema.TypeMap,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
// COMPAT(1.5.0)
// Deprecated fields.
"access_mode": {
Description: "Defines whether a volume should be available concurrently.",
Optional: true,
Deprecated: "use capability instead",
ConflictsWith: []string{"capability"},
Type: schema.TypeString,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
"single-node-reader-only",
"single-node-writer",
"multi-node-reader-only",
"multi-node-single-writer",
"multi-node-multi-writer",
}, false),
},
},
"attachment_mode": {
Description: "The storage API that will be used by the volume.",
Optional: true,
Deprecated: "use capability instead",
ConflictsWith: []string{"capability"},
Type: schema.TypeString,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
"block-device",
"file-system",
}, false),
},
},
},
SchemaVersion: 1,
StateUpgraders: []schema.StateUpgrader{
{
Type: resourceVolumeResourceV0().CoreConfigSchema().ImpliedType(),
Upgrade: resourceVolumeStateUpgradeV0,
Version: 0,
},
},
}
}
func toMapStringString(m interface{}) map[string]string {
mss := map[string]string{}
for k, v := range m.(map[string]interface{}) {
mss[k] = v.(string)
}
return mss
}
func resourceVolumeCreate(d *schema.ResourceData, meta interface{}) error {
providerConfig := meta.(ProviderConfig)
client := providerConfig.client
// Read capabilities maintaining backwards compatibility with the previous
// fields attachment_mode and access_mode.
capabilitySet, capabilitiesOk := d.GetOk("capability")
attachmentMode, attachmentModeOk := d.GetOk("attachment_mode")
accessMode, accessModeOk := d.GetOk("access_mode")
if !capabilitiesOk && !attachmentModeOk && !accessModeOk {
return errors.New(`one of "capability" or "access_mode" and "attachment_mode" must be configured`)
}
var capabilities []*api.CSIVolumeCapability
if capabilitiesOk {
var err error
capabilities, err = parseVolumeCapabilities(capabilitySet)
if err != nil {
return fmt.Errorf("failed to unpack capabilities: %v", err)
}
} else {
capabilities = []*api.CSIVolumeCapability{
{
AccessMode: api.CSIVolumeAccessMode(accessMode.(string)),
AttachmentMode: api.CSIVolumeAttachmentMode(attachmentMode.(string)),
},
}
}
topologyRequest, err := parseVolumeTopologyRequest(d.Get("topology_request"))
if err != nil {
return fmt.Errorf("failed to unpack topology request: %v", err)
}
volume := &api.CSIVolume{
ID: d.Get("volume_id").(string),
Name: d.Get("name").(string),
ExternalID: d.Get("external_id").(string),
RequestedCapabilities: capabilities,
RequestedTopologies: topologyRequest,
Secrets: toMapStringString(d.Get("secrets")),
Parameters: toMapStringString(d.Get("parameters")),
Context: toMapStringString(d.Get("context")),
PluginID: d.Get("plugin_id").(string),
// COMPAT(1.5.0)
// Maintain backwards compatibility.
AccessMode: capabilities[0].AccessMode,
AttachmentMode: capabilities[0].AttachmentMode,
}
// Unpack the mount_options if we have any and configure the volume struct.
mountOpts, ok := d.GetOk("mount_options")
if ok {
mountOptsList, ok := mountOpts.([]interface{})
if !ok || len(mountOptsList) != 1 {
return errors.New("failed to unpack mount_options configuration block")
}
mountOptsMap, ok := mountOptsList[0].(map[string]interface{})
if !ok {
return errors.New("failed to unpack mount_options configuration block")
}
volume.MountOptions = &api.CSIMountOptions{}
if val, ok := mountOptsMap["fs_type"].(string); ok {
volume.MountOptions.FSType = val
}
rawMountFlags := mountOptsMap["mount_flags"].([]interface{})
volume.MountOptions.MountFlags = make([]string, len(rawMountFlags))
for index, value := range rawMountFlags {
if val, ok := value.(string); ok {
volume.MountOptions.MountFlags[index] = val
}
}
}
// Register the volume
log.Printf("[DEBUG] registering volume %q in namespace %q", volume.ID, volume.Namespace)
opts := &api.WriteOptions{
Namespace: d.Get("namespace").(string),
}
if opts.Namespace == "" {
opts.Namespace = "default"
}
_, err = client.CSIVolumes().Register(volume, opts)
if err != nil {
return fmt.Errorf("error registering volume: %s", err)
}
log.Printf("[DEBUG] volume %q registered in namespace %q", volume.ID, volume.Namespace)
d.SetId(volume.ID)
return resourceVolumeRead(d, meta) // populate other computed attributes
}
func resourceVolumeDelete(d *schema.ResourceData, meta interface{}) error {
providerConfig := meta.(ProviderConfig)
client := providerConfig.client
// If deregistration is disabled, then do nothing
deregister_on_destroy := d.Get("deregister_on_destroy").(bool)
if !deregister_on_destroy {
log.Printf(
"[WARN] volume %q will not deregister since "+
"'deregister_on_destroy' is %t", d.Id(), deregister_on_destroy)
return nil
}
id := d.Id()
log.Printf("[DEBUG] deregistering volume: %q", id)
opts := &api.WriteOptions{
Namespace: d.Get("namespace").(string),
}
if opts.Namespace == "" {
opts.Namespace = "default"
}
err := client.CSIVolumes().Deregister(id, true, opts)
if err != nil {
return fmt.Errorf("error deregistering volume: %s", err)
}
return nil
}
func resourceVolumeRead(d *schema.ResourceData, meta interface{}) error {
providerConfig := meta.(ProviderConfig)
client := providerConfig.client
id := d.Id()
opts := &api.QueryOptions{
Namespace: d.Get("namespace").(string),
}
if opts.Namespace == "" {
opts.Namespace = "default"
}
log.Printf("[DEBUG] reading information for volume %q in namespace %q", id, opts.Namespace)
volume, _, err := client.CSIVolumes().Info(id, opts)
if err != nil {
// As of Nomad 0.4.1, the API client returns an error for 404
// rather than a nil result, so we must check this way.
if strings.Contains(err.Error(), "404") {
log.Printf("[DEBUG] volume %q does not exist, so removing", id)
d.SetId("")
return nil
}
return fmt.Errorf("error checking for volume: %s", err)
}
log.Printf("[DEBUG] found volume %q in namespace %q", volume.Name, volume.Namespace)
d.Set("name", volume.Name)
d.Set("controller_required", volume.ControllerRequired)
d.Set("controllers_expected", volume.ControllersExpected)
d.Set("controllers_healthy", volume.ControllersHealthy)
d.Set("controllers_healthy", volume.ControllersHealthy)
d.Set("plugin_provider", volume.Provider)
d.Set("plugin_provider_version", volume.ProviderVersion)
d.Set("nodes_healthy", volume.NodesHealthy)
d.Set("nodes_expected", volume.NodesExpected)
d.Set("schedulable", volume.Schedulable)
d.Set("topologies", flattenVolumeTopologies(volume.Topologies))
d.Set("topology_request", flattenVolumeTopologyRequests(volume.RequestedTopologies))
// The Nomad API redacts `mount_options` and `secrets`, so we don't update them
// with the response payload; they will remain as is.
return nil
}
func parseVolumeCapabilities(i interface{}) ([]*api.CSIVolumeCapability, error) {
capabilities := []*api.CSIVolumeCapability{}
capabilitySet, ok := i.(*schema.Set)
if !ok {
return nil, fmt.Errorf("invalid type %T, expected *schema.Set", i)
}
for _, capabilitySetItem := range capabilitySet.List() {
capabilityMap, ok := capabilitySetItem.(map[string]interface{})
if !ok {
return nil, fmt.Errorf("invalid type %T, expected map[string]interface{}", capabilitySetItem)
}
c := &api.CSIVolumeCapability{}
for k, v := range capabilityMap {
switch k {
case "access_mode":
c.AccessMode = api.CSIVolumeAccessMode(v.(string))
case "attachment_mode":
c.AttachmentMode = api.CSIVolumeAttachmentMode(v.(string))
}
}
capabilities = append(capabilities, c)
}
return capabilities, nil
}
// parseVolumeTopologyRequest parses a Terraform state representation of volume
// topology request into its Nomad API representation.
func parseVolumeTopologyRequest(i interface{}) (*api.CSITopologyRequest, error) {
req := &api.CSITopologyRequest{}
var err error
topologyRequestList, ok := i.([]interface{})
if !ok {
return nil, fmt.Errorf("invalid type %T for topology_request, expected []interface{}", i)
}
if len(topologyRequestList) == 0 {
return nil, nil
}
topologyMap, ok := topologyRequestList[0].(map[string]interface{})
if !ok {
return nil, fmt.Errorf("invalid type %T for topology_request item, expected map[string]interface{}", topologyRequestList[0])
}
if required, ok := topologyMap["required"]; ok {
req.Required, err = parseVolumeTopologies("required", required)
if err != nil {
return nil, fmt.Errorf("failed to parse required CSI topology: %v", err)
}
}
if preferred, ok := topologyMap["preferred"]; ok {
req.Preferred, err = parseVolumeTopologies("preferred", preferred)
if err != nil {
return nil, fmt.Errorf("failed to parse preferred CSI topology: %v", err)
}
}
return req, nil
}
// parseVolumeTopologis parses a Terraform state representation of volume
// topology into its Nomad API representation.
func parseVolumeTopologies(prefix string, i interface{}) ([]*api.CSITopology, error) {
var topologies []*api.CSITopology
topologiesList, ok := i.([]interface{})
if !ok {
return nil, fmt.Errorf("invalid type %T for %s.topology, expected []interface{}", i, prefix)
}
if len(topologiesList) == 0 {
return topologies, nil
}
topologiesListMap, ok := topologiesList[0].(map[string]interface{})
if !ok {
return nil, fmt.Errorf("invalid type %T for %s.topology, expected map[string]interface{}", topologiesList[0], prefix)
}
topologiesListMapList, ok := topologiesListMap["topology"].([]interface{})
if !ok {
return nil, fmt.Errorf("invalid type %T for %s.topology, expected []interface{}", topologiesListMap["topology"], prefix)
}
for j, topologyItem := range topologiesListMapList {
topologyItemMap, ok := topologyItem.(map[string]interface{})
if !ok {
return nil, fmt.Errorf(
"invalid type %T for %s.topology.%d, expected map[string]interface{}",
topologyItem, prefix, j)
}
segmentsMap, ok := topologyItemMap["segments"].(map[string]interface{})
if !ok {
return nil, fmt.Errorf(
"invalid type %T for %s.topology.%d.segments, expected map[string]interface{}",
topologyItemMap["segments"], prefix, j)
}
segmentsMapString := make(map[string]string, len(segmentsMap))
for k, v := range segmentsMap {
segmentsMapString[k] = v.(string)
}
topologies = append(topologies, &api.CSITopology{
Segments: segmentsMapString,
})
}
return topologies, nil
}
// flattenVolumeTopologies turns a list of Nomad API CSITopology structs into
// the flat representation used by Terraform.
func flattenVolumeTopologies(topologies []*api.CSITopology) []interface{} {
topologiesList := []interface{}{}
for _, topo := range topologies {
if topo == nil {
continue
}
topoItem := make(map[string]interface{})
topoItem["segments"] = topo.Segments
topologiesList = append(topologiesList, topoItem)
}
return topologiesList
}
// flattenVolumeTopologyRequests turns a list of Nomad API CSITopologyRequest structs into
// the flat representation used by Terraform.
func flattenVolumeTopologyRequests(topologyReqs *api.CSITopologyRequest) []interface{} {
if topologyReqs == nil {
return nil
}
topologyRequestList := make([]interface{}, 1)
topologyMap := make(map[string]interface{}, 1)
topologyRequestList[0] = topologyMap
if topologyReqs.Required != nil {
topologyMap["required"] = []any{
map[string]any{
"topology": flattenVolumeTopologies(topologyReqs.Required),
},
}
}
if topologyReqs.Preferred != nil {
topologyMap["preferred"] = []any{
map[string]any{
"topology": flattenVolumeTopologies(topologyReqs.Preferred),
},
}
}
return topologyRequestList
}
// resourceVolumeStateUpgradeV0 migrates a nomad_volume resource schema from v0 to v1.
func resourceVolumeStateUpgradeV0(_ context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
if val, ok := rawState["mount_options"]; ok {
rawState["mount_options"] = []interface{}{val}
}
return rawState, nil
}
// resourceVolumeResourceV0 returns the v0 schema for a nomad_volume.
func resourceVolumeResourceV0() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
ForceNew: true,
Type: schema.TypeString,
Optional: true,
Description: "The type of the volume. Currently, only 'csi' is supported.",
Default: "csi",
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"csi"}, false),
},
},
"namespace": {
ForceNew: true,
Description: "The namespace in which to create the volume.",
Optional: true,
Default: "default",
Type: schema.TypeString,
},
"volume_id": {
ForceNew: true,
Description: "The unique ID of the volume, how jobs will refer to the volume.",
Required: true,
Type: schema.TypeString,
},
"name": {
Description: "The display name of the volume.",
Required: true,
Type: schema.TypeString,
},
"plugin_id": {
ForceNew: true,
Description: "The ID of the CSI plugin that manages this volume.",
Required: true,
Type: schema.TypeString,
},
"external_id": {
ForceNew: true,
Description: "The ID of the physical volume from the storage provider.",
Required: true,
Type: schema.TypeString,
},
"access_mode": {
Description: "Defines whether a volume should be available concurrently.",
Required: true,
Type: schema.TypeString,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
"single-node-reader-only",
"single-node-writer",
"multi-node-reader-only",
"multi-node-single-writer",
"multi-node-multi-writer",
}, false),
},
},
"attachment_mode": {
Description: "The storage API that will be used by the volume.",
Required: true,
Type: schema.TypeString,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
"block-device",
"file-system",
}, false),
},
},
"mount_options": {
Description: "Options for mounting 'block-device' volumes without a pre-formatted file system.",
Optional: true,
Type: schema.TypeMap,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"fs_type": {
Description: "The file system type.",
Type: schema.TypeString,
},
"mount_flags": {
Description: "The flags passed to mount.",
Type: schema.TypeList,
},
},
},
},
"secrets": {
Description: "An optional key-value map of strings used as credentials for publishing and unpublishing volumes.",
Optional: true,
Type: schema.TypeMap,
Sensitive: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"parameters": {
Description: "An optional key-value map of strings passed directly to the CSI plugin to configure the volume.",
Optional: true,
Type: schema.TypeMap,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"context": {
Description: "An optional key-value map of strings passed directly to the CSI plugin to validate the volume.",
Optional: true,
Type: schema.TypeMap,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"deregister_on_destroy": {
Description: "If true, the volume will be deregistered on destroy.",
Optional: true,
Default: true,
Type: schema.TypeBool,
},
"controller_required": {
Computed: true,
Type: schema.TypeBool,
},
"controllers_expected": {
Computed: true,
Type: schema.TypeInt,
},
"controllers_healthy": {
Computed: true,
Type: schema.TypeInt,
},
"plugin_provider": {
Computed: true,
Type: schema.TypeString,
},
"plugin_provider_version": {
Computed: true,
Type: schema.TypeString,
},
"nodes_healthy": {
Computed: true,
Type: schema.TypeInt,
},
"nodes_expected": {
Computed: true,
Type: schema.TypeInt,
},
"schedulable": {
Computed: true,
Type: schema.TypeBool,
},
},
}
}