Skip to content

Commit

Permalink
Add volume attach tag with nova microversion 2.49
Browse files Browse the repository at this point in the history
  • Loading branch information
jichenjc committed May 14, 2024
1 parent 2747964 commit 5524317
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/resources/compute_volume_attach_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ The following arguments are supported:

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

* `tag` - (Optional) The tag of the volume attachment. Changing this
updates the tag of volume attachment. Requires microversion >= 2.49.

* `vendor_options` - (Optional) Map of additional vendor-specific options.
Supported options are described below.

Expand Down
1 change: 1 addition & 0 deletions openstack/compute_instance_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
computeV2InstanceCreateServerWithTagsMicroversion = "2.52"
computeV2TagsExtensionMicroversion = "2.26"
computeV2InstanceBlockDeviceVolumeTypeMicroversion = "2.67"
computeV2InstanceBlockDeviceVolumeAttachTagsMicroversion = "2.49"
computeV2InstanceBlockDeviceMultiattachMicroversion = "2.60"
)

Expand Down
13 changes: 13 additions & 0 deletions openstack/resource_openstack_compute_volume_attach_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ func resourceComputeVolumeAttachV2() *schema.Resource {
ForceNew: true,
},

"tag": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},

"vendor_options": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -118,6 +124,13 @@ func resourceComputeVolumeAttachV2Create(ctx context.Context, d *schema.Resource
VolumeID: volumeID,
}

// tag requires nova microversion 2.49. Only set when specified.
if v, ok := d.GetOk("tag"); ok {
tag := v.(string)
attachOpts.Tag = tag
computeClient.Microversion = computeV2InstanceBlockDeviceVolumeAttachTagsMicroversion
}

log.Printf("[DEBUG] openstack_compute_volume_attach_v2 attach options %s: %#v", instanceID, attachOpts)

multiattach := d.Get("multiattach").(bool)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ resource "openstack_compute_instance_v2" "instance_1" {
resource "openstack_compute_volume_attach_v2" "va_1" {
instance_id = "${openstack_compute_instance_v2.instance_1.id}"
volume_id = "${openstack_blockstorage_volume_v3.volume_1.id}"
tag = "test"
vendor_options {
ignore_volume_confirmation = true
}
Expand Down

0 comments on commit 5524317

Please sign in to comment.