-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathprovider.go
60 lines (53 loc) · 1.62 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
package main
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
// Provider creates a new JenkinsCI provider.
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"server_url": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("JENKINS_URL", nil),
Description: "The URL of the JenkinsCI server to connect to.",
},
"ca_cert": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("JENKINS_CA_CERT", nil),
Description: "The path to the JenkinsCi self-signed certificate.",
},
"username": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("JENKINS_USERNAME", nil),
Description: "Username to authenticate to JenkinsCI.",
},
"password": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("JENKINS_PASSWORD", nil),
Description: "Password to authenticate to JenkinsCI.",
},
},
ResourcesMap: map[string]*schema.Resource{
"jenkins_job": resourceJenkinsJob(),
},
ConfigureFunc: configureProvider,
}
}
func configureProvider(d *schema.ResourceData) (interface{}, error) {
config := Config{
ServerURL: d.Get("server_url").(string),
CACert: d.Get("ca_cert").(string),
Username: d.Get("username").(string),
Password: d.Get("password").(string),
}
client, err := config.getAPIClient()
if err != nil {
return nil, err
}
return client, nil
}