diff --git a/docs/data-sources/compute_instance.md b/docs/data-sources/compute_instance.md index 08831027de..7dec41c278 100644 --- a/docs/data-sources/compute_instance.md +++ b/docs/data-sources/compute_instance.md @@ -69,6 +69,7 @@ The `volume_attached` block supports: * `volume_id` - The volume id on that attachment. * `boot_index` - The volume boot index on that attachment. * `size` - The volume size on that attachment. +* `type` - The volume type on that attachment. * `pci_address` - The volume pci address on that attachment. The `scheduler_hints` block supports: diff --git a/huaweicloud/data_source_huaweicloud_compute_instance.go b/huaweicloud/data_source_huaweicloud_compute_instance.go index 925737392c..781a719e89 100644 --- a/huaweicloud/data_source_huaweicloud_compute_instance.go +++ b/huaweicloud/data_source_huaweicloud_compute_instance.go @@ -5,6 +5,7 @@ import ( "log" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/huaweicloud/golangsdk/openstack/blockstorage/v2/volumes" "github.com/huaweicloud/golangsdk/openstack/common/tags" "github.com/huaweicloud/golangsdk/openstack/ecs/v1/block_devices" "github.com/huaweicloud/golangsdk/openstack/ecs/v1/cloudservers" @@ -121,6 +122,10 @@ func DataSourceComputeInstance() *schema.Resource { Type: schema.TypeInt, Computed: true, }, + "type": { + Type: schema.TypeString, + Computed: true, + }, "pci_address": { Type: schema.TypeString, Computed: true, @@ -244,26 +249,41 @@ func dataSourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) err } // Set volume attached - instanceVolumes := []map[string]interface{}{} if len(server.VolumeAttached) > 0 { - for _, b := range server.VolumeAttached { + blockStorageClient, err := config.BlockStorageV3Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud EVS client: %s", err) + } + + bds := make([]map[string]interface{}, len(server.VolumeAttached)) + for i, b := range server.VolumeAttached { + // retrieve volume `size` and `type` + volumeInfo, err := volumes.Get(blockStorageClient, b.ID).Extract() + if err != nil { + return err + } + log.Printf("[DEBUG] Retrieved volume %s: %#v", b.ID, volumeInfo) + + // retrieve volume `pci_address` va, err := block_devices.Get(ecsClient, d.Id(), b.ID).Extract() if err != nil { return err } - log.Printf("[DEBUG] Retrieved volume attachment %s: %#v", d.Id(), va) - v := map[string]interface{}{ + log.Printf("[DEBUG] Retrieved block device %s: %#v", b.ID, va) + + bds[i] = map[string]interface{}{ "volume_id": b.ID, + "size": volumeInfo.Size, + "type": volumeInfo.VolumeType, "boot_index": va.BootIndex, - "size": va.Size, "pci_address": va.PciAddress, } - instanceVolumes = append(instanceVolumes, v) + if va.BootIndex == 0 { d.Set("system_disk_id", b.ID) } } - d.Set("volume_attached", instanceVolumes) + d.Set("volume_attached", bds) } // Set instance tags diff --git a/huaweicloud/resource_huaweicloud_compute_instance.go b/huaweicloud/resource_huaweicloud_compute_instance.go index 2f794da07d..f59eff06cd 100644 --- a/huaweicloud/resource_huaweicloud_compute_instance.go +++ b/huaweicloud/resource_huaweicloud_compute_instance.go @@ -250,6 +250,8 @@ func ResourceComputeInstanceV2() *schema.Resource { "enterprise_project_id": { Type: schema.TypeString, Optional: true, + ForceNew: true, + Computed: true, ConflictsWith: []string{"block_device", "metadata"}, }, "delete_disks_on_termination": {