-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.go
69 lines (59 loc) · 1.76 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
package main
import (
"net"
"os"
"github.com/hashicorp/terraform/helper/schema"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
)
func Provider() *schema.Provider {
return &schema.Provider{
Schema: providerSchema(),
ResourcesMap: providerResources(),
DataSourcesMap: providerDataSources(),
ConfigureFunc: providerConfigure,
}
}
// List of supported configuration fields for the provider.
// More info in https://github.com/hashicorp/terraform/blob/v0.6.6/helper/schema/schema.go#L29-L142
func providerSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"hosts": &schema.Schema{
Type: schema.TypeMap,
Required: true,
Description: "Host addresses of the SmartOS global zone.",
},
"user": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "User to authenticate with.",
},
}
}
func providerResources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"smartos-cluster_machine": resourceMachine(),
}
}
func providerDataSources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"smartos-cluster_image": datasourceImage(),
}
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
sshSocket := os.Getenv("SSH_AUTH_SOCK")
agentConnection, err := net.Dial("unix", sshSocket)
if err != nil {
return nil, err
}
authMethods := []ssh.AuthMethod{}
authMethods = append(authMethods, ssh.PublicKeysCallback(agent.NewClient(agentConnection).Signers))
client := SmartOSClient{
hosts: d.Get("hosts").(map[string]interface{}),
user: d.Get("user").(string),
agentConnection: agentConnection,
authMethods: authMethods,
clients: make(map[string]*ssh.Client),
}
return &client, nil
}