-
Notifications
You must be signed in to change notification settings - Fork 41
/
provider.go
63 lines (55 loc) · 1.69 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
package jenkins
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
// Provider creates a new Jenkins provider.
func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"server_url": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("JENKINS_URL", nil),
Description: "The URL of the Jenkins server to connect to.",
},
"ca_cert": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("JENKINS_CA_CERT", nil),
Description: "The path to the Jenkins self-signed certificate.",
},
"username": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("JENKINS_USERNAME", nil),
Description: "Username to authenticate to Jenkins.",
},
"password": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("JENKINS_PASSWORD", nil),
Description: "Password to authenticate to Jenkins.",
},
},
ResourcesMap: map[string]*schema.Resource{
"jenkins_folder": resourceJenkinsFolder(),
"jenkins_job": resourceJenkinsJob(),
},
ConfigureContextFunc: configureProvider,
}
}
func configureProvider(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
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 := newJenkinsClient(&config)
if err != nil {
return nil, diag.FromErr(err)
}
return client, nil
}