Skip to content

Commit

Permalink
Get Volume data-source improvement (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
pratikmota committed Apr 27, 2023
1 parent 7f7db69 commit f1c431e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions civo/datasource_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,24 @@ func dataSourceVolumeRead(_ context.Context, d *schema.ResourceData, m interface
log.Printf("[INFO] Getting the volume by id")
volume, err := apiClient.FindVolume(id.(string))
if err != nil {
return diag.Errorf("[ERR] failed to retrive volume: %s", err)
return diag.Errorf("[ERR] failed to retrieve volume: %s", err)
}

foundVolume = volume
} else if name, ok := d.GetOk("name"); ok {
log.Printf("[INFO] Getting the volume by name")
volume, err := apiClient.FindVolume(name.(string))
if err != nil {
return diag.Errorf("[ERR] failed to retrive volume: %s", err)
return diag.Errorf("[ERR] failed to retrieve volume: %s", err)
}

foundVolume = volume
}

//Check for nil pointer
if foundVolume == nil {
return diag.Errorf("[ERR] failed to retrieve volume")
}
d.SetId(foundVolume.ID)
d.Set("name", foundVolume.Name)
d.Set("size_gb", foundVolume.SizeGigabytes)
Expand Down
8 changes: 6 additions & 2 deletions examples/data-sources/civo_volume/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
data "civo_volume" "mysql" {
name = "database-mysql"
data "civo_volume" "myvolume" {
name = "test-volume-name"
}

output "volume_output" {
value = data.civo_volume.myvolume
}

0 comments on commit f1c431e

Please sign in to comment.