@@ -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
0 commit comments