From 4e073d5c32ed2cb8aa6a476b0e8161a0aa23dded Mon Sep 17 00:00:00 2001 From: Axel Ismirlian Date: Wed, 24 Sep 2025 16:58:34 -0500 Subject: [PATCH 1/7] Add volume id to volume data source --- .../power/data_source_ibm_pi_volume.go | 40 +++++++++++++++---- .../power/data_source_ibm_pi_volume_test.go | 12 +++--- website/docs/d/pi_volume.html.markdown | 10 +++-- 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_volume.go b/ibm/service/power/data_source_ibm_pi_volume.go index 7919fca0a4..ffae7ce75d 100644 --- a/ibm/service/power/data_source_ibm_pi_volume.go +++ b/ibm/service/power/data_source_ibm_pi_volume.go @@ -26,11 +26,22 @@ func DataSourceIBMPIVolume() *schema.Resource { Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, + Arg_VolumeID: { + AtLeastOneOf: []string{Arg_VolumeID, Arg_VolumeName}, + ConflictsWith: []string{Arg_VolumeName}, + Description: "The volume ID.", + Optional: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, + }, Arg_VolumeName: { - Description: "Volume Name to be used for pvminstances", - Required: true, - Type: schema.TypeString, - ValidateFunc: validation.NoZeroValues, + AtLeastOneOf: []string{Arg_VolumeID, Arg_VolumeName}, + ConflictsWith: []string{Arg_VolumeID}, + Deprecated: "The pi_volume_name field is deprecated. Please use pi_volume_id instead", + Description: "Volume Name to be used for pvminstances", + Optional: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, }, // Attributes @@ -152,6 +163,11 @@ func DataSourceIBMPIVolume() *schema.Resource { Set: schema.HashString, Type: schema.TypeSet, }, + Attr_VolumeName: { + Computed: true, + Description: "The name of the volume.", + Type: schema.TypeString, + }, Attr_VolumePool: { Computed: true, Description: "Volume pool, name of storage pool where the volume is located.", @@ -166,15 +182,22 @@ func DataSourceIBMPIVolume() *schema.Resource { } } -func dataSourceIBMPIVolumeRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func dataSourceIBMPIVolumeRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { return diag.FromErr(err) } cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + var volumeID string + if v, ok := d.GetOk(Arg_VolumeID); ok { + volumeID = v.(string) + } else if v, ok := d.GetOk(Arg_VolumeName); ok { + volumeID = v.(string) + } + volumeC := instance.NewIBMPIVolumeClient(ctx, sess, cloudInstanceID) - volumedata, err := volumeC.Get(d.Get(Arg_VolumeName).(string)) + volumedata, err := volumeC.Get(volumeID) if err != nil { return diag.FromErr(err) } @@ -205,14 +228,15 @@ func dataSourceIBMPIVolumeRead(ctx context.Context, d *schema.ResourceData, meta d.Set(Attr_OutOfBandDeleted, volumedata.OutOfBandDeleted) d.Set(Attr_PrimaryRole, volumedata.PrimaryRole) d.Set(Attr_ReplicationEnabled, volumedata.ReplicationEnabled) - d.Set(Attr_ReplicationType, volumedata.ReplicationType) if len(volumedata.ReplicationSites) > 0 { d.Set(Attr_ReplicationSites, volumedata.ReplicationSites) } d.Set(Attr_ReplicationStatus, volumedata.ReplicationStatus) - d.Set(Attr_State, volumedata.State) + d.Set(Attr_ReplicationType, volumedata.ReplicationType) d.Set(Attr_Shareable, volumedata.Shareable) d.Set(Attr_Size, volumedata.Size) + d.Set(Attr_State, volumedata.State) + d.Set(Attr_VolumeName, volumedata.Name) d.Set(Attr_VolumePool, volumedata.VolumePool) d.Set(Attr_WWN, volumedata.Wwn) diff --git a/ibm/service/power/data_source_ibm_pi_volume_test.go b/ibm/service/power/data_source_ibm_pi_volume_test.go index f40fb2dca8..74e9fc8a13 100644 --- a/ibm/service/power/data_source_ibm_pi_volume_test.go +++ b/ibm/service/power/data_source_ibm_pi_volume_test.go @@ -31,9 +31,9 @@ func TestAccIBMPIVolumeDataSource_basic(t *testing.T) { func testAccCheckIBMPIVolumeDataSourceConfig() string { return fmt.Sprintf(` data "ibm_pi_volume" "testacc_ds_volume" { - pi_volume_name = "%s" - pi_cloud_instance_id = "%s" - }`, acc.Pi_volume_name, acc.Pi_cloud_instance_id) + pi_cloud_instance_id = "%[1]s" + pi_volume_id = "%[2]s" + }`, acc.Pi_cloud_instance_id, acc.Pi_volume_id) } func TestAccIBMPIVolumeDataSource_replication(t *testing.T) { @@ -56,7 +56,7 @@ func TestAccIBMPIVolumeDataSource_replication(t *testing.T) { func testAccCheckIBMPIVolumeDataSourceReplicationConfig() string { return fmt.Sprintf(` data "ibm_pi_volume" "testacc_ds_volume" { - pi_volume_name = "%s" - pi_cloud_instance_id = "%s" - }`, acc.Pi_replication_volume_name, acc.Pi_cloud_instance_id) + pi_cloud_instance_id = "%[1]s" + pi_volume_name = "%[2]s" + }`, acc.Pi_cloud_instance_id, acc.Pi_replication_volume_id) } diff --git a/website/docs/d/pi_volume.html.markdown b/website/docs/d/pi_volume.html.markdown index 90501d6e3b..8d52dc7973 100644 --- a/website/docs/d/pi_volume.html.markdown +++ b/website/docs/d/pi_volume.html.markdown @@ -1,7 +1,7 @@ --- subcategory: "Power Systems" layout: "ibm" -page_title: "IBM: pi_volume" +page_title: "IBM: ibm_pi_volume" description: |- Manages a volume in the Power Virtual Server cloud. --- @@ -16,8 +16,8 @@ The following example retrieves information about the `volume_1` volume that is ```terraform data "ibm_pi_volume" "ds_volume" { - pi_volume_name = "volume_1" pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b" + pi_volume_id = "7f8e2a9d-3b4c-4e4f-8e8d-f7e7e1e23456" } ``` @@ -42,14 +42,15 @@ Example usage: Review the argument references that you can specify for your data source. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. -- `pi_volume_name` - (Required, String) The name of the volume for which you want to retrieve detailed information. +- `pi_volume_id` - (Optional, String) The volume ID. +- `pi_volume_name` - (Deprecated, Optional, String) The name of the volume. Please use `pi_volume_id` instead. ## Attribute Reference In addition to all argument reference list, you can access the following attribute references after your data source is created. -- `auxiliary` - (Boolean) Indicates if the volume is auxiliary. - `auxiliary_volume_name` - (String) The auxiliary volume name. +- `auxiliary` - (Boolean) Indicates if the volume is auxiliary. - `bootable` - (Boolean) Indicates if the volume is boot capable. - `consistency_group_name` - (String) Consistency group name if volume is a part of volume group. - `creation_date` - (String) Date of volume creation. @@ -72,5 +73,6 @@ In addition to all argument reference list, you can access the following attribu - `size` - (Integer) The size of the volume in GB. - `state` - (String) The state of the volume. - `user_tags` - (List) List of user tags attached to the resource. +- `volume_name` - (String) The name of the volume. - `volume_pool` - (String) Volume pool, name of storage pool where the volume is located. - `wwn` - (String) The world wide name of the volume. From 3301c13a795a10e0437a7d6a77bda0e35c1f27d9 Mon Sep 17 00:00:00 2001 From: Axel Ismirlian Date: Wed, 24 Sep 2025 16:58:56 -0500 Subject: [PATCH 2/7] Add volumes data source --- ibm/acctest/acctest.go | 10 +- ibm/provider/provider.go | 1 + .../power/data_source_ibm_pi_volumes.go | 250 ++++++++++++++++++ .../power/data_source_ibm_pi_volumes_test.go | 35 +++ ibm/service/power/ibm_pi_constants.go | 1 + website/docs/d/pi_volumes.html.markdown | 78 ++++++ 6 files changed, 370 insertions(+), 5 deletions(-) create mode 100644 ibm/service/power/data_source_ibm_pi_volumes.go create mode 100644 ibm/service/power/data_source_ibm_pi_volumes_test.go create mode 100644 website/docs/d/pi_volumes.html.markdown diff --git a/ibm/acctest/acctest.go b/ibm/acctest/acctest.go index 4ce6af4577..65405ac999 100644 --- a/ibm/acctest/acctest.go +++ b/ibm/acctest/acctest.go @@ -250,7 +250,7 @@ var ( Pi_placement_group_name string Pi_remote_id string Pi_remote_type string - Pi_replication_volume_name string + Pi_replication_volume_id string Pi_resource_group_id string Pi_route_filter_id string Pi_route_id string @@ -1267,10 +1267,10 @@ func init() { fmt.Println("[INFO] Set the environment variable PI_VOLUME_ID for testing ibm_pi_volume_flash_copy_mappings resource else it is set to default value 'terraform-test-power'") } - Pi_replication_volume_name = os.Getenv("PI_REPLICATION_VOLUME_NAME") - if Pi_replication_volume_name == "" { - Pi_replication_volume_name = "terraform-test-power" - fmt.Println("[INFO] Set the environment variable PI_REPLICATION_VOLUME_NAME for testing ibm_pi_volume resource else it is set to default value 'terraform-test-power'") + Pi_replication_volume_id = os.Getenv("PI_REPLICATION_VOLUME_ID") + if Pi_replication_volume_id == "" { + Pi_replication_volume_id = "terraform-test-power" + fmt.Println("[INFO] Set the environment variable PI_REPLICATION_VOLUME_ID for testing ibm_pi_volume resource else it is set to default value 'terraform-test-power'") } Pi_volume_onboarding_source_crn = os.Getenv("PI_VOLUME_ONBARDING_SOURCE_CRN") diff --git a/ibm/provider/provider.go b/ibm/provider/provider.go index 0c39d5413f..ea0725ce6a 100644 --- a/ibm/provider/provider.go +++ b/ibm/provider/provider.go @@ -791,6 +791,7 @@ func Provider() *schema.Provider { "ibm_pi_volume_snapshot": power.DataSourceIBMPIVolumeSnapshot(), "ibm_pi_volume_snapshots": power.DataSourceIBMPIVolumeSnapshots(), "ibm_pi_volume": power.DataSourceIBMPIVolume(), + "ibm_pi_volumes": power.DataSourceIBMPIVolumes(), "ibm_pi_workspace": power.DatasourceIBMPIWorkspace(), "ibm_pi_workspaces": power.DatasourceIBMPIWorkspaces(), diff --git a/ibm/service/power/data_source_ibm_pi_volumes.go b/ibm/service/power/data_source_ibm_pi_volumes.go new file mode 100644 index 0000000000..f39c7605bf --- /dev/null +++ b/ibm/service/power/data_source_ibm_pi_volumes.go @@ -0,0 +1,250 @@ +// Copyright IBM Corp. 2017, 2021 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package power + +import ( + "context" + "log" + + "github.com/IBM-Cloud/power-go-client/clients/instance" + "github.com/IBM-Cloud/power-go-client/power/models" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/hashicorp/go-uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func DataSourceIBMPIVolumes() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceIBMPIVolumesRead, + Schema: map[string]*schema.Schema{ + // Arguments + Arg_CloudInstanceID: { + Description: "The GUID of the service instance associated with an account.", + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, + }, + + // Attributes + Attr_Volumes: { + Computed: true, + Description: "List of all volumes.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + Attr_Auxiliary: { + Computed: true, + Description: "Indicates if the volume is auxiliary or not.", + Type: schema.TypeBool, + }, + Attr_AuxiliaryVolumeName: { + Computed: true, + Description: "The auxiliary volume name.", + Type: schema.TypeString, + }, + Attr_Bootable: { + Computed: true, + Description: "Indicates if the volume is boot capable.", + Type: schema.TypeBool, + }, + Attr_CRN: { + Computed: true, + Description: "The CRN of this resource.", + Type: schema.TypeString, + }, + Attr_ConsistencyGroupName: { + Computed: true, + Description: "Consistency group name if volume is a part of volume group.", + Type: schema.TypeString, + }, + Attr_CreationDate: { + Computed: true, + Description: "Date volume was created.", + Type: schema.TypeString, + }, + Attr_DiskType: { + Computed: true, + Description: "The disk type that is used for the volume.", + Type: schema.TypeString, + }, + Attr_FreezeTime: { + Computed: true, + Description: "The freeze time of remote copy.", + Type: schema.TypeString, + }, + Attr_GroupID: { + Computed: true, + Description: "The volume group id in which the volume belongs.", + Type: schema.TypeString, + }, + Attr_ID: { + Computed: true, + Description: "The unique identifier of the volume.", + Type: schema.TypeString, + }, + Attr_IOThrottleRate: { + Computed: true, + Description: "Amount of iops assigned to the volume", + Type: schema.TypeString, + }, + Attr_LastUpdateDate: { + Computed: true, + Description: "The last updated date of the volume.", + Type: schema.TypeString, + }, + Attr_MasterVolumeName: { + Computed: true, + Description: "The master volume name.", + Type: schema.TypeString, + }, + Attr_MirroringState: { + Computed: true, + Description: "Mirroring state for replication enabled volume.", + Type: schema.TypeString, + }, + Attr_OutOfBandDeleted: { + Computed: true, + Description: "Indicates if the volume does not exist on storage controller.", + Type: schema.TypeBool, + }, + Attr_PrimaryRole: { + Computed: true, + Description: "Indicates whether master/auxiliary volume is playing the primary role.", + Type: schema.TypeString, + }, + Attr_ReplicationEnabled: { + Computed: true, + Description: "Indicates if the volume should be replication enabled or not.", + Type: schema.TypeBool, + }, + Attr_ReplicationSites: { + Computed: true, + Description: "List of replication sites for volume replication.", + Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeList, + }, + Attr_ReplicationStatus: { + Computed: true, + Description: "The replication status of the volume.", + Type: schema.TypeString, + }, + Attr_ReplicationType: { + Computed: true, + Description: "The replication type of the volume, metro or global.", + Type: schema.TypeString, + }, + Attr_Shareable: { + Computed: true, + Description: "Indicates if the volume is shareable between VMs.", + Type: schema.TypeBool, + }, + Attr_Size: { + Computed: true, + Description: "The size of the volume in GB.", + Type: schema.TypeInt, + }, + Attr_State: { + Computed: true, + Description: "The state of the volume.", + Type: schema.TypeString, + }, + Attr_UserTags: { + Computed: true, + Description: "List of user tags attached to the resource.", + Elem: &schema.Schema{Type: schema.TypeString}, + Set: schema.HashString, + Type: schema.TypeSet, + }, + Attr_VolumeName: { + Computed: true, + Description: "The name of the volume.", + Type: schema.TypeString, + }, + Attr_VolumePool: { + Computed: true, + Description: "Volume pool, name of storage pool where the volume is located.", + Type: schema.TypeString, + }, + Attr_WWN: { + Computed: true, + Description: "The world wide name of the volume.", + Type: schema.TypeString, + }, + }, + }, + Type: schema.TypeList, + }, + }, + } +} + +func dataSourceIBMPIVolumesRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { + sess, err := meta.(conns.ClientSession).IBMPISession() + if err != nil { + return diag.FromErr(err) + } + + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + volumeC := instance.NewIBMPIVolumeClient(ctx, sess, cloudInstanceID) + volumeData, err := volumeC.GetAll() + if err != nil { + return diag.FromErr(err) + } + + var clientgenU, _ = uuid.GenerateUUID() + d.SetId(clientgenU) + d.Set(Attr_Volumes, flattenVolumes(volumeData.Volumes, meta)) + return nil +} + +func flattenVolumes(list []*models.VolumeReference, meta any) []map[string]any { + log.Printf("Calling the flattenVolumeGroups call with list %d", len(list)) + result := make([]map[string]any, 0, len(list)) + for _, i := range list { + volume := map[string]any{ + Attr_Auxiliary: *i.Auxiliary, + Attr_AuxiliaryVolumeName: i.AuxVolumeName, + Attr_Bootable: *i.Bootable, + Attr_ConsistencyGroupName: i.ConsistencyGroupName, + Attr_CreationDate: i.CreationDate.String(), + Attr_DiskType: *i.DiskType, + Attr_GroupID: i.GroupID, + Attr_ID: *i.VolumeID, + Attr_IOThrottleRate: i.IoThrottleRate, + Attr_LastUpdateDate: i.LastUpdateDate.String(), + Attr_MasterVolumeName: i.MasterVolumeName, + Attr_MirroringState: i.MirroringState, + Attr_OutOfBandDeleted: i.OutOfBandDeleted, + Attr_PrimaryRole: i.PrimaryRole, + Attr_ReplicationEnabled: *i.ReplicationEnabled, + Attr_ReplicationStatus: i.ReplicationStatus, + Attr_ReplicationType: i.ReplicationType, + Attr_Shareable: *i.Shareable, + Attr_Size: *i.Size, + Attr_State: *i.State, + Attr_VolumeName: *i.Name, + Attr_VolumePool: i.VolumePool, + Attr_WWN: *i.Wwn, + } + if i.FreezeTime != nil { + volume[Attr_FreezeTime] = i.FreezeTime.String() + } + if len(i.ReplicationSites) > 0 { + volume[Attr_ReplicationSites] = i.ReplicationSites + } + volumeCRN := string(i.Crn) + if volumeCRN != "" { + volume[Attr_CRN] = i.Crn + tags, err := flex.GetGlobalTagsUsingCRN(meta, volumeCRN, "", UserTagType) + if err != nil { + log.Printf("Error on get of pi volume (%s) user_tags: %s", *i.VolumeID, err) + } + volume[Attr_UserTags] = tags + } + result = append(result, volume) + } + return result +} diff --git a/ibm/service/power/data_source_ibm_pi_volumes_test.go b/ibm/service/power/data_source_ibm_pi_volumes_test.go new file mode 100644 index 0000000000..83f2300b92 --- /dev/null +++ b/ibm/service/power/data_source_ibm_pi_volumes_test.go @@ -0,0 +1,35 @@ +// Copyright IBM Corp. 2024 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package power_test + +import ( + "fmt" + "testing" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccIBMPIVolumesDataSourceBasic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMPIVolumesDataSourceConfigBasic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_pi_volumes.volumes", "id"), + ), + }, + }, + }) +} + +func testAccCheckIBMPIVolumesDataSourceConfigBasic() string { + return fmt.Sprintf(` + data "ibm_pi_volumes" "volumes" { + pi_cloud_instance_id = "%s" + } + `, acc.Pi_cloud_instance_id) +} diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index 26e3b47130..1a6f10c8ab 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -550,6 +550,7 @@ const ( Attr_VolumeGroupStatus = "volume_group_status" Attr_VolumeID = "volume_id" Attr_VolumeIDs = "volume_ids" + Attr_VolumeName = "volume_name" Attr_VolumePool = "volume_pool" Attr_Volumes = "volumes" Attr_VolumeSnapshots = "volume_snapshots" diff --git a/website/docs/d/pi_volumes.html.markdown b/website/docs/d/pi_volumes.html.markdown new file mode 100644 index 0000000000..5808689103 --- /dev/null +++ b/website/docs/d/pi_volumes.html.markdown @@ -0,0 +1,78 @@ +--- +subcategory: "Power Systems" +layout: "ibm" +page_title: "IBM: ibm_pi_volumes" +description: |- + Manages a volume in the Power Virtual Server cloud. +--- + +# ibm_pi_volumes + +Retrieves information about all persistent storage volumes that in a Power Systems Virtual Server workspace. For more information, about managin a volume, see [moving data to the cloud](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-moving-data-to-the-cloud). + +## Example Usage + +The following example retrieves information about all volumes present in a Power Systems Virtual Server workspace. + +```terraform +data "ibm_pi_volumes" "ds_volume" { + pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b" +} +``` + +### Notes + +- Please find [supported Regions](https://cloud.ibm.com/apidocs/power-cloud#endpoint) for endpoints. +- If a Power cloud instance is provisioned at `lon04`, The provider level attributes should be as follows: + - `region` - `lon` + - `zone` - `lon04` + +Example usage: + + ```terraform + provider "ibm" { + region = "lon" + zone = "lon04" + } + ``` + +## Argument Reference + +Review the argument references that you can specify for your data source. + +- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. + +## Attribute Reference + +In addition to all argument reference list, you can access the following attribute references after your data source is created. + +- `volumes` - (List) The list of volumes. + + Nested schema for `volumes`: + - `auxiliary_volume_name` - (String) The auxiliary volume name. + - `auxiliary` - (Boolean) Indicates if the volume is auxiliary. + - `bootable` - (Boolean) Indicates if the volume is boot capable. + - `consistency_group_name` - (String) Consistency group name if volume is a part of volume group. + - `creation_date` - (String) Date of volume creation. + - `crn` - (String) The CRN of this resource. + - `disk_type` - (String) The disk type that is used for the volume. + - `freeze_time` - (String) Time of remote copy relationship. + - `group_id` - (String) The volume group id in which the volume belongs. + - `id` - (String) The unique identifier of the volume. + - `io_throttle_rate` - (String) Amount of iops assigned to the volume. + - `last_update_date` - (String) The date when the volume last updated. + - `master_volume_name` - (String) The master volume name. + - `mirroring_state` - (String) Mirroring state for replication enabled volume. + - `out_of_band_deleted` - (Bool) Indicates if the volume does not exist on storage controller. + - `primary_role` - (String) Indicates whether `master`/`auxiliary` volume is playing the primary role. + - `replication_enabled` - (Boolean) Indicates if the volume should be replication enabled or not. + - `replication_sites` - (List) List of replication sites for volume replication. + - `replication_status` - (String) The replication status of the volume. + - `replication_type` - (String) The replication type of the volume, `metro` or `global`. + - `shareable` - (String) Indicates if the volume is shareable between VMs. + - `size` - (Integer) The size of the volume in GB. + - `state` - (String) The state of the volume. + - `user_tags` - (List) List of user tags attached to the resource. + - `volume_name` - (String) The name of the volume. + - `volume_pool` - (String) Volume pool, name of storage pool where the volume is located. + - `wwn` - (String) The world wide name of the volume. From da858f5b3808de677d2b3dec4ac343c9128e7682 Mon Sep 17 00:00:00 2001 From: Axel Ismirlian Date: Thu, 25 Sep 2025 08:03:15 -0500 Subject: [PATCH 3/7] Add new error handling to volume data sources --- ibm/service/power/data_source_ibm_pi_volume.go | 9 +++++++-- ibm/service/power/data_source_ibm_pi_volumes.go | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_volume.go b/ibm/service/power/data_source_ibm_pi_volume.go index ffae7ce75d..83a53c2cc5 100644 --- a/ibm/service/power/data_source_ibm_pi_volume.go +++ b/ibm/service/power/data_source_ibm_pi_volume.go @@ -5,6 +5,7 @@ package power import ( "context" + "fmt" "log" "github.com/IBM-Cloud/power-go-client/clients/instance" @@ -185,7 +186,9 @@ func DataSourceIBMPIVolume() *schema.Resource { func dataSourceIBMPIVolumeRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("IBMPISession failed: %s", err.Error()), "(Data) ibm_pi_volume", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) @@ -199,7 +202,9 @@ func dataSourceIBMPIVolumeRead(ctx context.Context, d *schema.ResourceData, meta volumeC := instance.NewIBMPIVolumeClient(ctx, sess, cloudInstanceID) volumedata, err := volumeC.Get(volumeID) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Get failed: %s", err.Error()), "(Data) ibm_pi_volume", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(*volumedata.VolumeID) diff --git a/ibm/service/power/data_source_ibm_pi_volumes.go b/ibm/service/power/data_source_ibm_pi_volumes.go index f39c7605bf..3b0419ce43 100644 --- a/ibm/service/power/data_source_ibm_pi_volumes.go +++ b/ibm/service/power/data_source_ibm_pi_volumes.go @@ -5,6 +5,7 @@ package power import ( "context" + "fmt" "log" "github.com/IBM-Cloud/power-go-client/clients/instance" @@ -184,14 +185,18 @@ func DataSourceIBMPIVolumes() *schema.Resource { func dataSourceIBMPIVolumesRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("IBMPISession failed: %s", err.Error()), "(Data) ibm_pi_volumes", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) volumeC := instance.NewIBMPIVolumeClient(ctx, sess, cloudInstanceID) volumeData, err := volumeC.GetAll() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetAll failed: %s", err.Error()), "(Data) ibm_pi_volumes", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } var clientgenU, _ = uuid.GenerateUUID() From b16b1c2aef321a989e91d840f40e1be92a45bf49 Mon Sep 17 00:00:00 2001 From: Axel Ismirlian Date: Thu, 25 Sep 2025 08:05:05 -0500 Subject: [PATCH 4/7] Fix typo --- website/docs/d/pi_volume.html.markdown | 2 +- website/docs/d/pi_volumes.html.markdown | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/d/pi_volume.html.markdown b/website/docs/d/pi_volume.html.markdown index 8d52dc7973..cac9efa499 100644 --- a/website/docs/d/pi_volume.html.markdown +++ b/website/docs/d/pi_volume.html.markdown @@ -8,7 +8,7 @@ description: |- # ibm_pi_volume -Retrieves information about a persistent storage volume that is mounted to a Power Systems Virtual Server instance. For more information, about managin a volume, see [moving data to the cloud](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-moving-data-to-the-cloud). +Retrieves information about a persistent storage volume that is mounted to a Power Systems Virtual Server instance. For more information, about managing a volume, see [moving data to the cloud](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-moving-data-to-the-cloud). ## Example Usage diff --git a/website/docs/d/pi_volumes.html.markdown b/website/docs/d/pi_volumes.html.markdown index 5808689103..476593f809 100644 --- a/website/docs/d/pi_volumes.html.markdown +++ b/website/docs/d/pi_volumes.html.markdown @@ -8,7 +8,7 @@ description: |- # ibm_pi_volumes -Retrieves information about all persistent storage volumes that in a Power Systems Virtual Server workspace. For more information, about managin a volume, see [moving data to the cloud](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-moving-data-to-the-cloud). +Retrieves information about all persistent storage volumes that in a Power Systems Virtual Server workspace. For more information, about managing a volume, see [moving data to the cloud](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-moving-data-to-the-cloud). ## Example Usage From 3742d55908c5a2601e077fa9c21d2239568e16a5 Mon Sep 17 00:00:00 2001 From: Axel Ismirlian Date: Fri, 26 Sep 2025 12:12:50 -0500 Subject: [PATCH 5/7] Add volume type attribute --- ibm/service/power/data_source_ibm_pi_volume.go | 10 ++++++++-- .../power/data_source_ibm_pi_volume_test.go | 2 +- ibm/service/power/data_source_ibm_pi_volumes.go | 17 +++++++++++------ ibm/service/power/ibm_pi_constants.go | 2 +- website/docs/d/pi_volume.html.markdown | 3 ++- website/docs/d/pi_volumes.html.markdown | 7 ++++--- 6 files changed, 27 insertions(+), 14 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_volume.go b/ibm/service/power/data_source_ibm_pi_volume.go index 83a53c2cc5..1ac06fc0b1 100644 --- a/ibm/service/power/data_source_ibm_pi_volume.go +++ b/ibm/service/power/data_source_ibm_pi_volume.go @@ -164,7 +164,7 @@ func DataSourceIBMPIVolume() *schema.Resource { Set: schema.HashString, Type: schema.TypeSet, }, - Attr_VolumeName: { + Attr_Name: { Computed: true, Description: "The name of the volume.", Type: schema.TypeString, @@ -174,6 +174,11 @@ func DataSourceIBMPIVolume() *schema.Resource { Description: "Volume pool, name of storage pool where the volume is located.", Type: schema.TypeString, }, + Attr_VolumeType: { + Computed: true, + Description: "The name of storage template used to create the volume.", + Type: schema.TypeString, + }, Attr_WWN: { Computed: true, Description: "The world wide name of the volume.", @@ -230,6 +235,7 @@ func dataSourceIBMPIVolumeRead(ctx context.Context, d *schema.ResourceData, meta d.Set(Attr_LastUpdateDate, volumedata.LastUpdateDate.String()) d.Set(Attr_MasterVolumeName, volumedata.MasterVolumeName) d.Set(Attr_MirroringState, volumedata.MirroringState) + d.Set(Attr_Name, volumedata.Name) d.Set(Attr_OutOfBandDeleted, volumedata.OutOfBandDeleted) d.Set(Attr_PrimaryRole, volumedata.PrimaryRole) d.Set(Attr_ReplicationEnabled, volumedata.ReplicationEnabled) @@ -241,8 +247,8 @@ func dataSourceIBMPIVolumeRead(ctx context.Context, d *schema.ResourceData, meta d.Set(Attr_Shareable, volumedata.Shareable) d.Set(Attr_Size, volumedata.Size) d.Set(Attr_State, volumedata.State) - d.Set(Attr_VolumeName, volumedata.Name) d.Set(Attr_VolumePool, volumedata.VolumePool) + d.Set(Attr_VolumeType, volumedata.VolumeType) d.Set(Attr_WWN, volumedata.Wwn) return nil diff --git a/ibm/service/power/data_source_ibm_pi_volume_test.go b/ibm/service/power/data_source_ibm_pi_volume_test.go index 74e9fc8a13..0512e8c27c 100644 --- a/ibm/service/power/data_source_ibm_pi_volume_test.go +++ b/ibm/service/power/data_source_ibm_pi_volume_test.go @@ -57,6 +57,6 @@ func testAccCheckIBMPIVolumeDataSourceReplicationConfig() string { return fmt.Sprintf(` data "ibm_pi_volume" "testacc_ds_volume" { pi_cloud_instance_id = "%[1]s" - pi_volume_name = "%[2]s" + pi_volume_id = "%[2]s" }`, acc.Pi_cloud_instance_id, acc.Pi_replication_volume_id) } diff --git a/ibm/service/power/data_source_ibm_pi_volumes.go b/ibm/service/power/data_source_ibm_pi_volumes.go index 3b0419ce43..68d82d947b 100644 --- a/ibm/service/power/data_source_ibm_pi_volumes.go +++ b/ibm/service/power/data_source_ibm_pi_volumes.go @@ -106,6 +106,11 @@ func DataSourceIBMPIVolumes() *schema.Resource { Description: "Mirroring state for replication enabled volume.", Type: schema.TypeString, }, + Attr_Name: { + Computed: true, + Description: "The name of the volume.", + Type: schema.TypeString, + }, Attr_OutOfBandDeleted: { Computed: true, Description: "Indicates if the volume does not exist on storage controller.", @@ -159,14 +164,14 @@ func DataSourceIBMPIVolumes() *schema.Resource { Set: schema.HashString, Type: schema.TypeSet, }, - Attr_VolumeName: { + Attr_VolumePool: { Computed: true, - Description: "The name of the volume.", + Description: "The name of storage pool where the volume is located.", Type: schema.TypeString, }, - Attr_VolumePool: { + Attr_VolumeType: { Computed: true, - Description: "Volume pool, name of storage pool where the volume is located.", + Description: "The name of storage template used to create the volume.", Type: schema.TypeString, }, Attr_WWN: { @@ -206,7 +211,6 @@ func dataSourceIBMPIVolumesRead(ctx context.Context, d *schema.ResourceData, met } func flattenVolumes(list []*models.VolumeReference, meta any) []map[string]any { - log.Printf("Calling the flattenVolumeGroups call with list %d", len(list)) result := make([]map[string]any, 0, len(list)) for _, i := range list { volume := map[string]any{ @@ -222,6 +226,7 @@ func flattenVolumes(list []*models.VolumeReference, meta any) []map[string]any { Attr_LastUpdateDate: i.LastUpdateDate.String(), Attr_MasterVolumeName: i.MasterVolumeName, Attr_MirroringState: i.MirroringState, + Attr_Name: *i.Name, Attr_OutOfBandDeleted: i.OutOfBandDeleted, Attr_PrimaryRole: i.PrimaryRole, Attr_ReplicationEnabled: *i.ReplicationEnabled, @@ -230,8 +235,8 @@ func flattenVolumes(list []*models.VolumeReference, meta any) []map[string]any { Attr_Shareable: *i.Shareable, Attr_Size: *i.Size, Attr_State: *i.State, - Attr_VolumeName: *i.Name, Attr_VolumePool: i.VolumePool, + Attr_VolumeType: i.VolumeType, Attr_WWN: *i.Wwn, } if i.FreezeTime != nil { diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index 1a6f10c8ab..b82927bbbc 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -550,12 +550,12 @@ const ( Attr_VolumeGroupStatus = "volume_group_status" Attr_VolumeID = "volume_id" Attr_VolumeIDs = "volume_ids" - Attr_VolumeName = "volume_name" Attr_VolumePool = "volume_pool" Attr_Volumes = "volumes" Attr_VolumeSnapshots = "volume_snapshots" Attr_VolumesSnapshots = "volume_snapshots" Attr_VolumeStatus = "volume_status" + Attr_VolumeType = "volume_type" Attr_VPCCRNs = "vpc_crns" Attr_VPCEnabled = "vpc_enabled" Attr_WorkloadType = "workload_type" diff --git a/website/docs/d/pi_volume.html.markdown b/website/docs/d/pi_volume.html.markdown index cac9efa499..53cc6d2eff 100644 --- a/website/docs/d/pi_volume.html.markdown +++ b/website/docs/d/pi_volume.html.markdown @@ -74,5 +74,6 @@ In addition to all argument reference list, you can access the following attribu - `state` - (String) The state of the volume. - `user_tags` - (List) List of user tags attached to the resource. - `volume_name` - (String) The name of the volume. -- `volume_pool` - (String) Volume pool, name of storage pool where the volume is located. +- `volume_pool` - (String) The name of storage pool where the volume is located. +- `volume_type` - (String) The name of storage template used to create the volume. - `wwn` - (String) The world wide name of the volume. diff --git a/website/docs/d/pi_volumes.html.markdown b/website/docs/d/pi_volumes.html.markdown index 476593f809..c8d9cea68e 100644 --- a/website/docs/d/pi_volumes.html.markdown +++ b/website/docs/d/pi_volumes.html.markdown @@ -3,12 +3,12 @@ subcategory: "Power Systems" layout: "ibm" page_title: "IBM: ibm_pi_volumes" description: |- - Manages a volume in the Power Virtual Server cloud. + Manages volumes in the Power Virtual Server cloud. --- # ibm_pi_volumes -Retrieves information about all persistent storage volumes that in a Power Systems Virtual Server workspace. For more information, about managing a volume, see [moving data to the cloud](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-moving-data-to-the-cloud). +Retrieves information about all persistent storage volumes that in a Power Systems Virtual Server workspace. For more information, about managing volumes, see [moving data to the cloud](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-moving-data-to-the-cloud). ## Example Usage @@ -74,5 +74,6 @@ In addition to all argument reference list, you can access the following attribu - `state` - (String) The state of the volume. - `user_tags` - (List) List of user tags attached to the resource. - `volume_name` - (String) The name of the volume. - - `volume_pool` - (String) Volume pool, name of storage pool where the volume is located. + - `volume_pool` - (String) The name of storage pool where the volume is located. + - `volume_type` - (String) The name of storage template used to create the volume. - `wwn` - (String) The world wide name of the volume. From 0ac13b8478438e6c794fc777c68822e4b4804bec Mon Sep 17 00:00:00 2001 From: Axel Ismirlian Date: Fri, 26 Sep 2025 12:23:02 -0500 Subject: [PATCH 6/7] Fix documentation --- website/docs/d/pi_volume.html.markdown | 2 +- website/docs/d/pi_volumes.html.markdown | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/d/pi_volume.html.markdown b/website/docs/d/pi_volume.html.markdown index 53cc6d2eff..44fb267f73 100644 --- a/website/docs/d/pi_volume.html.markdown +++ b/website/docs/d/pi_volume.html.markdown @@ -63,6 +63,7 @@ In addition to all argument reference list, you can access the following attribu - `last_update_date` - (String) The date when the volume last updated. - `master_volume_name` - (String) The master volume name. - `mirroring_state` - (String) Mirroring state for replication enabled volume. +- `name` - (String) The name of the volume. - `out_of_band_deleted` - (Bool) Indicates if the volume does not exist on storage controller. - `primary_role` - (String) Indicates whether `master`/`auxiliary` volume is playing the primary role. - `replication_enabled` - (Boolean) Indicates if the volume should be replication enabled or not. @@ -73,7 +74,6 @@ In addition to all argument reference list, you can access the following attribu - `size` - (Integer) The size of the volume in GB. - `state` - (String) The state of the volume. - `user_tags` - (List) List of user tags attached to the resource. -- `volume_name` - (String) The name of the volume. - `volume_pool` - (String) The name of storage pool where the volume is located. - `volume_type` - (String) The name of storage template used to create the volume. - `wwn` - (String) The world wide name of the volume. diff --git a/website/docs/d/pi_volumes.html.markdown b/website/docs/d/pi_volumes.html.markdown index c8d9cea68e..323f2082e8 100644 --- a/website/docs/d/pi_volumes.html.markdown +++ b/website/docs/d/pi_volumes.html.markdown @@ -63,6 +63,7 @@ In addition to all argument reference list, you can access the following attribu - `last_update_date` - (String) The date when the volume last updated. - `master_volume_name` - (String) The master volume name. - `mirroring_state` - (String) Mirroring state for replication enabled volume. + - `name` - (String) The name of the volume. - `out_of_band_deleted` - (Bool) Indicates if the volume does not exist on storage controller. - `primary_role` - (String) Indicates whether `master`/`auxiliary` volume is playing the primary role. - `replication_enabled` - (Boolean) Indicates if the volume should be replication enabled or not. @@ -73,7 +74,6 @@ In addition to all argument reference list, you can access the following attribu - `size` - (Integer) The size of the volume in GB. - `state` - (String) The state of the volume. - `user_tags` - (List) List of user tags attached to the resource. - - `volume_name` - (String) The name of the volume. - `volume_pool` - (String) The name of storage pool where the volume is located. - `volume_type` - (String) The name of storage template used to create the volume. - `wwn` - (String) The world wide name of the volume. From 38c70d78a4ef9bbe641cca9144b2177b00255519 Mon Sep 17 00:00:00 2001 From: Axel Ismirlian Date: Mon, 6 Oct 2025 10:58:57 -0500 Subject: [PATCH 7/7] Update deprecation message --- website/docs/d/pi_volume.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/d/pi_volume.html.markdown b/website/docs/d/pi_volume.html.markdown index 44fb267f73..61a449e0f5 100644 --- a/website/docs/d/pi_volume.html.markdown +++ b/website/docs/d/pi_volume.html.markdown @@ -43,7 +43,7 @@ Review the argument references that you can specify for your data source. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. - `pi_volume_id` - (Optional, String) The volume ID. -- `pi_volume_name` - (Deprecated, Optional, String) The name of the volume. Please use `pi_volume_id` instead. +- `pi_volume_name` - (Deprecated, Optional, String) The id of the volume. Passing the name of the volume could fail or fetch stale data. Please pass an id and use `pi_volume_id` instead. ## Attribute Reference