-
Notifications
You must be signed in to change notification settings - Fork 2
/
data_source_file_storage_volume.go
56 lines (45 loc) · 1.27 KB
/
data_source_file_storage_volume.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package provider
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceFileStorageVolume() *schema.Resource {
ds := dataSourceSchemaFromResourceSchema(resourceFileStorageVolume().Schema)
ds["id"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "The ID of this resource.",
}
ds["size"] = &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The size of the volume in bytes.",
}
return &schema.Resource{
ReadContext: dataSourceFileStorageVolumeRead,
Schema: ds,
Description: "Fetch details for a individual file storage volume.",
}
}
func dataSourceFileStorageVolumeRead(
ctx context.Context,
d *schema.ResourceData,
meta interface{},
) diag.Diagnostics {
m := meta.(*Meta)
var diags diag.Diagnostics
fsv, _, err := m.Core.FileStorageVolumes.GetByID(ctx, d.Get("id").(string))
if err != nil {
return diag.FromErr(err)
}
_ = d.Set("name", fsv.Name)
_ = d.Set("size", fsv.Size)
_ = d.Set("nfs_location", fsv.NFSLocation)
err = d.Set("associations", stringSliceToSchemaSet(fsv.Associations))
if err != nil {
diags = append(diags, diag.FromErr(err)...)
}
d.SetId(fsv.ID)
return diags
}