forked from hashicorp/terraform-provider-vsphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_vsphere_tag.go
44 lines (38 loc) · 1.01 KB
/
data_source_vsphere_tag.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
package vsphere
import "github.com/hashicorp/terraform/helper/schema"
func dataSourceVSphereTag() *schema.Resource {
return &schema.Resource{
Read: dataSourceVSphereTagRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Description: "The display name of the tag.",
Required: true,
},
"category_id": {
Type: schema.TypeString,
Description: "The unique identifier of the parent category for this tag.",
Required: true,
},
"description": {
Type: schema.TypeString,
Description: "The description of the tag.",
Computed: true,
},
},
}
}
func dataSourceVSphereTagRead(d *schema.ResourceData, meta interface{}) error {
client, err := meta.(*VSphereClient).TagsClient()
if err != nil {
return err
}
name := d.Get("name").(string)
categoryID := d.Get("category_id").(string)
tagID, err := tagByName(client, name, categoryID)
if err != nil {
return err
}
d.SetId(tagID)
return resourceVSphereTagRead(d, meta)
}