Skip to content
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

Compute v2: Enable Multiattach Volumes #442

Merged
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
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