-
Notifications
You must be signed in to change notification settings - Fork 7
/
data_source_network_backing.go
55 lines (44 loc) · 1.15 KB
/
data_source_network_backing.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
package main
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
hcx "github.com/adeleporte/terraform-provider-hcx/hcx"
)
func dataSourceNetworkBacking() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceNetworkBackingRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"vcuuid": {
Type: schema.TypeString,
Required: true,
},
"entityid": {
Type: schema.TypeString,
Computed: true,
},
"network_type": {
Type: schema.TypeString,
Optional: true,
Default: "DistributedVirtualPortgroup",
},
},
}
}
func dataSourceNetworkBackingRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
var diags diag.Diagnostics
client := m.(*hcx.Client)
network := d.Get("name").(string)
vcuuid := d.Get("vcuuid").(string)
network_type := d.Get("network_type").(string)
res, err := hcx.GetNetworkBacking(client, vcuuid, network, network_type)
if err != nil {
return diag.FromErr(err)
}
d.SetId(res.EntityID)
return diags
}