-
Notifications
You must be signed in to change notification settings - Fork 16
/
data_source_transip_private_network.go
72 lines (63 loc) · 1.76 KB
/
data_source_transip_private_network.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
66
67
68
69
70
71
72
package main
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/transip/gotransip/v6/repository"
"github.com/transip/gotransip/v6/vps"
)
func dataSourcePrivateNetwork() *schema.Resource {
return &schema.Resource{
Read: dataSourcePrivateNetworkRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Description: "The unique private network name",
Required: true,
ForceNew: true,
},
"description": {
Type: schema.TypeString,
Description: "The custom name that can be set by customer.",
Computed: true,
},
"is_blocked": {
Type: schema.TypeString,
Description: "If the Private Network is administratively blocked.",
Computed: true,
},
"is_locked": {
Type: schema.TypeString,
Description: "When locked, another process is already working with this privatenetwork.",
Computed: true,
},
"vps_names": {
Type: schema.TypeList,
Description: "The VPSes in this private network.",
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
}
}
func dataSourcePrivateNetworkRead(d *schema.ResourceData, m interface{}) error {
client := m.(repository.Client)
repository := vps.PrivateNetworkRepository{Client: client}
name := d.Get("name").(string)
p, err := repository.GetByName(name)
if err != nil {
return fmt.Errorf("failed to lookup private network %q: %s", name, err)
}
var vpsNames []string
for _, vpsName := range p.VpsNames {
vpsNames = append(vpsNames, vpsName)
}
d.SetId(name)
d.Set("name", name)
d.Set("description", p.Description)
d.Set("is_blocked", p.IsBlocked)
d.Set("is_locked", p.IsLocked)
d.Set("vps_names", vpsNames)
return nil
}