This repository has been archived by the owner on Oct 10, 2022. It is now read-only.
forked from josenk/terraform-provider-esxi
/
provider.go
68 lines (62 loc) · 1.81 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
package esxi
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"log"
"os"
)
func init() {
// Terraform is already adding the timestamp for us
log.SetFlags(log.Lshortfile)
log.SetPrefix(fmt.Sprintf("pid-%d-", os.Getpid()))
}
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"esxi_hostname": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
DefaultFunc: schema.EnvDefaultFunc("", "esxi"),
Description: "The esxi hostname or IP address.",
},
"esxi_hostport": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("esxi_hostport", "22"),
Description: "ssh port.",
},
"esxi_username": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("esxi_username", "root"),
Description: "esxi ssh username.",
},
"esxi_password": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("esxi_password", "unset"),
Description: "esxi ssh password.",
},
},
ResourcesMap: map[string]*schema.Resource{
"esxi_guest": resourceGUEST(),
"esxi_resource_pool": resourceRESOURCEPOOL(),
"esxi_virtual_disk": resourceVIRTUALDISK(),
},
ConfigureFunc: configureProvider,
}
}
func configureProvider(d *schema.ResourceData) (interface{}, error) {
config := Config{
esxiHostName: d.Get("esxi_hostname").(string),
esxiHostPort: d.Get("esxi_hostport").(string),
esxiUserName: d.Get("esxi_username").(string),
esxiPassword: d.Get("esxi_password").(string),
}
if err := config.validateEsxiCreds(); err != nil {
return nil, err
}
return &config, nil
}