Skip to content

Commit

Permalink
Compute v2: Enable Multiattach Volumes
Browse files Browse the repository at this point in the history
This commit allows instances to attach multiattach volumes
by adding a new argument called "multiattach". When set, the
compute client will use Microversion 2.60, which enables multiattach
support in the Compute/Nova API.
  • Loading branch information
jtopjian committed Oct 16, 2018
1 parent ce4d90d commit e4f08e7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
10 changes: 10 additions & 0 deletions openstack/resource_openstack_compute_volume_attach_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ func resourceComputeVolumeAttachV2() *schema.Resource {
Computed: true,
Optional: true,
},

"multiattach": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
},
}
}
Expand All @@ -78,6 +84,10 @@ func resourceComputeVolumeAttachV2Create(d *schema.ResourceData, meta interface{

log.Printf("[DEBUG] Creating volume attachment: %#v", attachOpts)

if v := d.Get("multiattach").(bool); v {
computeClient.Microversion = "2.60"
}

attachment, err := volumeattach.Create(computeClient, instanceId, attachOpts).Extract()
if err != nil {
return err
Expand Down
42 changes: 42 additions & 0 deletions website/docs/r/compute_volume_attach_v2.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,45 @@ output "volume devices" {
}
```

### Using Multiattach-enabled volumes

Multiattach Volumes are dependent upon your OpenStack cloud and not all
clouds support multiattach.

```hcl
resource "openstack_blockstorage_volume_v3" "volume_1" {
name = "volume_1"
size = 1
multiattach = true
}
resource "openstack_compute_instance_v2" "instance_1" {
name = "instance_1"
security_groups = ["default"]
}
resource "openstack_compute_instance_v2" "instance_2" {
name = "instance_2"
security_groups = ["default"]
}
resource "openstack_compute_volume_attach_v2" "va_1" {
instance_id = "${openstack_compute_instance_v2.instance_1.id}"
volume_id = "${openstack_blockstorage_volume_v2.volume_1.id}"
multiattach = true
}
resource "openstack_compute_volume_attach_v2" "va_2" {
instance_id = "${openstack_compute_instance_v2.instance_2.id}"
volume_id = "${openstack_blockstorage_volume_v2.volume_1.id}"
multiattach = true
depends_on = ["openstack_compute_volume_attach_v2.va_1"]
}
```

It is recommended to use `depends_on` for the attach resources
to enforce the volume attachments to happen one at a time.

## Argument Reference

Expand All @@ -114,6 +153,8 @@ The following arguments are supported:
to update the device upon subsequent applying which will cause the volume
to be detached and reattached indefinitely. Please use with caution.

* `multiattach` - (Optional) Enable attachment of multiattach-capable volumes.

## Attributes Reference

The following attributes are exported:
Expand All @@ -124,6 +165,7 @@ The following attributes are exported:
* `device` - See Argument Reference above. _NOTE_: The correctness of this
information is dependent upon the hypervisor in use. In some cases, this
should not be used as an authoritative piece of information.
* `multiattach` - See Argument Reference above.

## Import

Expand Down

0 comments on commit e4f08e7

Please sign in to comment.