/
provider.go
83 lines (77 loc) · 1.78 KB
/
provider.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
73
74
75
76
77
78
79
80
81
82
83
package lvslb
import (
"os"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
const nullStr string = "null"
const (
defaultFirewallPort = 8080
)
// Provider lvslb for terraform.
func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"firewall_ip": {
Type: schema.TypeString,
Required: true,
},
"port": {
Type: schema.TypeInt,
Optional: true,
Default: defaultFirewallPort,
},
"https": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"insecure": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"login": {
Type: schema.TypeString,
Optional: true,
},
"password": {
Type: schema.TypeString,
Optional: true,
},
"vault_enable": {
Type: schema.TypeBool,
Optional: true,
ConflictsWith: []string{"login", "password"},
},
"vault_path": {
Type: schema.TypeString,
Optional: true,
Default: "lvs",
},
"vault_key": {
Type: schema.TypeString,
Optional: true,
Default: "",
},
},
ResourcesMap: map[string]*schema.Resource{
"lvslb_ipvs": resourceIpvs(),
},
ConfigureFunc: configureProvider,
}
}
func configureProvider(d *schema.ResourceData) (interface{}, error) {
config := Config{
firewallIP: d.Get("firewall_ip").(string),
firewallPort: d.Get("port").(int),
https: d.Get("https").(bool),
insecure: d.Get("insecure").(bool),
logname: os.Getenv("USER"),
login: d.Get("login").(string),
password: d.Get("password").(string),
vaultEnable: d.Get("vault_enable").(bool),
vaultPath: d.Get("vault_path").(string),
vaultKey: d.Get("vault_key").(string),
}
return config.Client()
}