forked from hashicorp/terraform-provider-vsphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_vsphere_content_library_item.go
38 lines (35 loc) · 1.2 KB
/
data_source_vsphere_content_library_item.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
package vsphere
import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-vsphere/vsphere/internal/helper/contentlibrary"
"github.com/terraform-providers/terraform-provider-vsphere/vsphere/internal/helper/provider"
)
func dataSourceVSphereContentLibraryItem() *schema.Resource {
return &schema.Resource{
Read: dataSourceVSphereContentLibraryItemRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The name of the content library item.",
},
"library_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "ID of the content library to contain item",
},
},
}
}
func dataSourceVSphereContentLibraryItemRead(d *schema.ResourceData, meta interface{}) error {
rc := meta.(*VSphereClient).restClient
lib, _ := contentlibrary.FromID(rc, d.Get("library_id").(string))
item, err := contentlibrary.ItemFromName(rc, lib, d.Get("name").(string))
if err != nil {
return provider.ProviderError(d.Get("name").(string), "dataSourceVSphereContentLibraryItemRead", err)
}
d.SetId(item.ID)
return nil
}