-
Notifications
You must be signed in to change notification settings - Fork 670
/
data_source_ibm_is_volume_profile.go
65 lines (54 loc) · 1.44 KB
/
data_source_ibm_is_volume_profile.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
57
58
59
60
61
62
63
64
65
// Copyright IBM Corp. 2017, 2021 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package vpc
import (
"github.com/IBM/vpc-go-sdk/vpcv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
const (
isVolumeProfile = "name"
isVolumeProfileFamily = "family"
)
func DataSourceIBMISVolumeProfile() *schema.Resource {
return &schema.Resource{
Read: dataSourceIBMISVolumeProfileRead,
Schema: map[string]*schema.Schema{
isVolumeProfile: {
Type: schema.TypeString,
Required: true,
Description: "Volume profile name",
},
isVolumeProfileFamily: {
Type: schema.TypeString,
Computed: true,
Description: "Volume profile family",
},
},
}
}
func dataSourceIBMISVolumeProfileRead(d *schema.ResourceData, meta interface{}) error {
name := d.Get(isVolumeProfile).(string)
err := volumeProfileGet(d, meta, name)
if err != nil {
return err
}
return nil
}
func volumeProfileGet(d *schema.ResourceData, meta interface{}, name string) error {
sess, err := vpcClient(meta)
if err != nil {
return err
}
getVolumeProfileOptions := &vpcv1.GetVolumeProfileOptions{
Name: &name,
}
profile, _, err := sess.GetVolumeProfile(getVolumeProfileOptions)
if err != nil {
return err
}
// For lack of anything better, compose our id from profile name.
d.SetId(*profile.Name)
d.Set(isVolumeProfile, *profile.Name)
d.Set(isVolumeProfileFamily, *profile.Family)
return nil
}