Skip to content
Open
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: 5 additions & 5 deletions ibm/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ var (
Pi_placement_group_id 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
Expand Down Expand Up @@ -1274,10 +1274,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")
Expand Down
53 changes: 43 additions & 10 deletions ibm/service/power/data_source_ibm_pi_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package power

import (
"context"
"fmt"
"log"

"github.com/IBM-Cloud/power-go-client/clients/instance"
Expand All @@ -26,11 +27,20 @@ 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,
},
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,
},

// Attributes
Expand Down Expand Up @@ -152,11 +162,21 @@ func DataSourceIBMPIVolume() *schema.Resource {
Set: schema.HashString,
Type: schema.TypeSet,
},
Attr_Name: {
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_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.",
Expand All @@ -166,17 +186,28 @@ 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)
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)
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)
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)
Expand All @@ -202,18 +233,20 @@ 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)
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_VolumePool, volumedata.VolumePool)
d.Set(Attr_VolumeType, volumedata.VolumeType)
d.Set(Attr_WWN, volumedata.Wwn)

return nil
Expand Down
12 changes: 6 additions & 6 deletions ibm/service/power/data_source_ibm_pi_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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_id = "%[2]s"
}`, acc.Pi_cloud_instance_id, acc.Pi_replication_volume_id)
}
1 change: 1 addition & 0 deletions ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ const (
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"
Expand Down
15 changes: 9 additions & 6 deletions website/docs/d/pi_volume.html.markdown
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
---
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.
---

# 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

The following example retrieves information about the `volume_1` volume that is mounted to the Power Systems Virtual Server instance with the ID.

```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"
}
```

Expand All @@ -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 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

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.
Expand All @@ -62,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.
Expand All @@ -72,5 +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_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.
Loading