Skip to content

resource/volume: add "mount_options" argument to volume resource. #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 36 additions & 10 deletions nomad/resource_volume.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nomad

import (
"errors"
"fmt"
"log"
"strings"
Expand Down Expand Up @@ -100,14 +101,23 @@ func resourceVolume() *schema.Resource {
},
},

// "mount_options": {
// Description: "Options for mounting 'block-device' volumes without a pre-formatted file system.",
// Optional: true,
// Type: schema.TypeMap,
// Elem: &schema.Schema{
// Type: schema.TypeString,
// },
// },
"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.",
Expand Down Expand Up @@ -204,8 +214,6 @@ func resourceVolumeCreate(d *schema.ResourceData, meta interface{}) error {
ns = "default"
}

// TODO: mountOptions := d.Get("mount_options")

volume := &api.CSIVolume{
ID: d.Get("volume_id").(string),
Name: d.Get("name").(string),
Expand All @@ -218,6 +226,23 @@ func resourceVolumeCreate(d *schema.ResourceData, meta interface{}) error {
PluginID: d.Get("plugin_id").(string),
}

// Unpack the mount_options if we have any and configure the volume struct.
mountOpts, ok := d.GetOk("mount_options")
if ok {
mountOptsMap, ok := mountOpts.(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
}
if val, ok := mountOptsMap["mount_flags"].([]string); ok {
volume.MountOptions.MountFlags = val
}
}

// Register the volume
log.Printf("[DEBUG] registering volume %q in namespace %q", volume.ID, volume.Namespace)
_, err := client.CSIVolumes().Register(volume, nil)
Expand Down Expand Up @@ -296,6 +321,7 @@ func resourceVolumeRead(d *schema.ResourceData, meta interface{}) error {
d.Set("nodes_healthy", volume.NodesHealthy)
d.Set("nodes_expected", volume.NodesExpected)
d.Set("schedulable", volume.Schedulable)
d.Set("mount_options", volume.MountOptions)

return nil
}
3 changes: 3 additions & 0 deletions website/docs/r/volume.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ The following arguments are supported:
- `multi-node-single-writer`
- `multi-node-multi-writer`
- `attachment_mode`: `(string: <required>)` The storage API that will be used by the volume.
- `mount_options`: `(map[string]interface: optional)` Options for mounting `block-device` volumes without a pre-formatted file system.
- `fs_type`: `(string: optional)` - The file system type.
- `mount_flags`: `[]string: optional` - The flags passed to `mount`.
- `secrets`: `(map[string]string: optional)` An optional key-value map of strings used as credentials for publishing and unpublishing volumes.
- `parameters`: `(map[string]string: optional)` An optional key-value map of strings passed directly to the CSI plugin to configure the volume.
- `context`: `(map[string]string: optional)` An optional key-value map of strings passed directly to the CSI plugin to validate the volume.
Expand Down