Skip to content
Closed
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_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
Expand Down Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions ibm/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),

Expand Down
55 changes: 45 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,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
Expand Down Expand Up @@ -152,11 +164,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 +188,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 +235,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)
}
Loading
Loading