Skip to content

Commit 4e073d5

Browse files
committed
Add volume id to volume data source
1 parent 9c48db3 commit 4e073d5

File tree

3 files changed

+44
-18
lines changed

3 files changed

+44
-18
lines changed

ibm/service/power/data_source_ibm_pi_volume.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,22 @@ func DataSourceIBMPIVolume() *schema.Resource {
2626
Type: schema.TypeString,
2727
ValidateFunc: validation.NoZeroValues,
2828
},
29+
Arg_VolumeID: {
30+
AtLeastOneOf: []string{Arg_VolumeID, Arg_VolumeName},
31+
ConflictsWith: []string{Arg_VolumeName},
32+
Description: "The volume ID.",
33+
Optional: true,
34+
Type: schema.TypeString,
35+
ValidateFunc: validation.NoZeroValues,
36+
},
2937
Arg_VolumeName: {
30-
Description: "Volume Name to be used for pvminstances",
31-
Required: true,
32-
Type: schema.TypeString,
33-
ValidateFunc: validation.NoZeroValues,
38+
AtLeastOneOf: []string{Arg_VolumeID, Arg_VolumeName},
39+
ConflictsWith: []string{Arg_VolumeID},
40+
Deprecated: "The pi_volume_name field is deprecated. Please use pi_volume_id instead",
41+
Description: "Volume Name to be used for pvminstances",
42+
Optional: true,
43+
Type: schema.TypeString,
44+
ValidateFunc: validation.NoZeroValues,
3445
},
3546

3647
// Attributes
@@ -152,6 +163,11 @@ func DataSourceIBMPIVolume() *schema.Resource {
152163
Set: schema.HashString,
153164
Type: schema.TypeSet,
154165
},
166+
Attr_VolumeName: {
167+
Computed: true,
168+
Description: "The name of the volume.",
169+
Type: schema.TypeString,
170+
},
155171
Attr_VolumePool: {
156172
Computed: true,
157173
Description: "Volume pool, name of storage pool where the volume is located.",
@@ -166,15 +182,22 @@ func DataSourceIBMPIVolume() *schema.Resource {
166182
}
167183
}
168184

169-
func dataSourceIBMPIVolumeRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
185+
func dataSourceIBMPIVolumeRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
170186
sess, err := meta.(conns.ClientSession).IBMPISession()
171187
if err != nil {
172188
return diag.FromErr(err)
173189
}
174190

175191
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
192+
var volumeID string
193+
if v, ok := d.GetOk(Arg_VolumeID); ok {
194+
volumeID = v.(string)
195+
} else if v, ok := d.GetOk(Arg_VolumeName); ok {
196+
volumeID = v.(string)
197+
}
198+
176199
volumeC := instance.NewIBMPIVolumeClient(ctx, sess, cloudInstanceID)
177-
volumedata, err := volumeC.Get(d.Get(Arg_VolumeName).(string))
200+
volumedata, err := volumeC.Get(volumeID)
178201
if err != nil {
179202
return diag.FromErr(err)
180203
}
@@ -205,14 +228,15 @@ func dataSourceIBMPIVolumeRead(ctx context.Context, d *schema.ResourceData, meta
205228
d.Set(Attr_OutOfBandDeleted, volumedata.OutOfBandDeleted)
206229
d.Set(Attr_PrimaryRole, volumedata.PrimaryRole)
207230
d.Set(Attr_ReplicationEnabled, volumedata.ReplicationEnabled)
208-
d.Set(Attr_ReplicationType, volumedata.ReplicationType)
209231
if len(volumedata.ReplicationSites) > 0 {
210232
d.Set(Attr_ReplicationSites, volumedata.ReplicationSites)
211233
}
212234
d.Set(Attr_ReplicationStatus, volumedata.ReplicationStatus)
213-
d.Set(Attr_State, volumedata.State)
235+
d.Set(Attr_ReplicationType, volumedata.ReplicationType)
214236
d.Set(Attr_Shareable, volumedata.Shareable)
215237
d.Set(Attr_Size, volumedata.Size)
238+
d.Set(Attr_State, volumedata.State)
239+
d.Set(Attr_VolumeName, volumedata.Name)
216240
d.Set(Attr_VolumePool, volumedata.VolumePool)
217241
d.Set(Attr_WWN, volumedata.Wwn)
218242

ibm/service/power/data_source_ibm_pi_volume_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ func TestAccIBMPIVolumeDataSource_basic(t *testing.T) {
3131
func testAccCheckIBMPIVolumeDataSourceConfig() string {
3232
return fmt.Sprintf(`
3333
data "ibm_pi_volume" "testacc_ds_volume" {
34-
pi_volume_name = "%s"
35-
pi_cloud_instance_id = "%s"
36-
}`, acc.Pi_volume_name, acc.Pi_cloud_instance_id)
34+
pi_cloud_instance_id = "%[1]s"
35+
pi_volume_id = "%[2]s"
36+
}`, acc.Pi_cloud_instance_id, acc.Pi_volume_id)
3737
}
3838

3939
func TestAccIBMPIVolumeDataSource_replication(t *testing.T) {
@@ -56,7 +56,7 @@ func TestAccIBMPIVolumeDataSource_replication(t *testing.T) {
5656
func testAccCheckIBMPIVolumeDataSourceReplicationConfig() string {
5757
return fmt.Sprintf(`
5858
data "ibm_pi_volume" "testacc_ds_volume" {
59-
pi_volume_name = "%s"
60-
pi_cloud_instance_id = "%s"
61-
}`, acc.Pi_replication_volume_name, acc.Pi_cloud_instance_id)
59+
pi_cloud_instance_id = "%[1]s"
60+
pi_volume_name = "%[2]s"
61+
}`, acc.Pi_cloud_instance_id, acc.Pi_replication_volume_id)
6262
}

website/docs/d/pi_volume.html.markdown

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
subcategory: "Power Systems"
33
layout: "ibm"
4-
page_title: "IBM: pi_volume"
4+
page_title: "IBM: ibm_pi_volume"
55
description: |-
66
Manages a volume in the Power Virtual Server cloud.
77
---
@@ -16,8 +16,8 @@ The following example retrieves information about the `volume_1` volume that is
1616

1717
```terraform
1818
data "ibm_pi_volume" "ds_volume" {
19-
pi_volume_name = "volume_1"
2019
pi_cloud_instance_id = "49fba6c9-23f8-40bc-9899-aca322ee7d5b"
20+
pi_volume_id = "7f8e2a9d-3b4c-4e4f-8e8d-f7e7e1e23456"
2121
}
2222
```
2323

@@ -42,14 +42,15 @@ Example usage:
4242
Review the argument references that you can specify for your data source.
4343

4444
- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account.
45-
- `pi_volume_name` - (Required, String) The name of the volume for which you want to retrieve detailed information.
45+
- `pi_volume_id` - (Optional, String) The volume ID.
46+
- `pi_volume_name` - (Deprecated, Optional, String) The name of the volume. Please use `pi_volume_id` instead.
4647

4748
## Attribute Reference
4849

4950
In addition to all argument reference list, you can access the following attribute references after your data source is created.
5051

51-
- `auxiliary` - (Boolean) Indicates if the volume is auxiliary.
5252
- `auxiliary_volume_name` - (String) The auxiliary volume name.
53+
- `auxiliary` - (Boolean) Indicates if the volume is auxiliary.
5354
- `bootable` - (Boolean) Indicates if the volume is boot capable.
5455
- `consistency_group_name` - (String) Consistency group name if volume is a part of volume group.
5556
- `creation_date` - (String) Date of volume creation.
@@ -72,5 +73,6 @@ In addition to all argument reference list, you can access the following attribu
7273
- `size` - (Integer) The size of the volume in GB.
7374
- `state` - (String) The state of the volume.
7475
- `user_tags` - (List) List of user tags attached to the resource.
76+
- `volume_name` - (String) The name of the volume.
7577
- `volume_pool` - (String) Volume pool, name of storage pool where the volume is located.
7678
- `wwn` - (String) The world wide name of the volume.

0 commit comments

Comments
 (0)