forked from hashicorp/terraform-provider-vsphere
/
data_source_vsphere_vapp_container.go
43 lines (39 loc) · 1.13 KB
/
data_source_vsphere_vapp_container.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
package vsphere
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-vsphere/vsphere/internal/helper/vappcontainer"
)
func dataSourceVSphereVAppContainer() *schema.Resource {
return &schema.Resource{
Read: dataSourceVSphereVAppContainerRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "The name of the vApp container.",
},
"datacenter_id": {
Type: schema.TypeString,
Required: true,
Description: "The Managed Object ID of the datacenter.",
},
},
}
}
func dataSourceVSphereVAppContainerRead(d *schema.ResourceData, meta interface{}) error {
client, err := resourceVSphereVAppContainerClient(meta)
if err != nil {
return err
}
dc, err := datacenterFromID(client, d.Get("datacenter_id").(string))
if err != nil {
return fmt.Errorf("cannot locate datacenter: %s", err)
}
vc, err := vappcontainer.FromPath(client, d.Get("name").(string), dc)
if err != nil {
return fmt.Errorf("cannot locate vApp Container: %s", err)
}
d.SetId(vc.Reference().Value)
return nil
}