/
provider.go
79 lines (71 loc) · 2.64 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
package teamcity
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)
//Provider is the plugin entry point
func Provider() terraform.ResourceProvider {
return &schema.Provider{
ResourcesMap: map[string]*schema.Resource{
"teamcity_project": resourceProject(),
"teamcity_vcs_root_git": resourceVcsRootGit(),
"teamcity_build_config": resourceBuildConfig(),
"teamcity_snapshot_dependency": resourceSnapshotDependency(),
"teamcity_artifact_dependency": resourceArtifactDependency(),
"teamcity_build_trigger_vcs": resourceBuildTriggerVcs(),
"teamcity_build_trigger_build_finish": resourceBuildTriggerBuildFinish(),
"teamcity_build_trigger_schedule": resourceBuildTriggerSchedule(),
"teamcity_agent_requirement": resourceAgentRequirement(),
"teamcity_feature_commit_status_publisher": resourceFeatureCommitStatusPublisher(),
"teamcity_group": resourceGroup(),
"teamcity_group_role_assignment": resourceGroupRoleAssignment(),
},
DataSourcesMap: map[string]*schema.Resource{
"teamcity_project": dataSourceProject(),
},
Schema: map[string]*schema.Schema{
"address": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("TEAMCITY_ADDR", nil),
},
"token": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"username", "password"},
DefaultFunc: schema.EnvDefaultFunc("TEAMCITY_TOKEN", nil),
},
"username": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"token"},
DefaultFunc: schema.EnvDefaultFunc("TEAMCITY_USER", nil),
},
"password": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"token"},
DefaultFunc: schema.EnvDefaultFunc("TEAMCITY_PASSWORD", nil),
},
},
ConfigureFunc: providerConfigure,
}
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := Config{
Address: d.Get("address").(string),
Username: d.Get("username").(string),
Password: d.Get("password").(string),
}
if v, ok := d.GetOk("token"); ok && v.(string) != "" {
config.Token = v.(string)
} else {
config.Username = d.Get("username").(string)
config.Password = d.Get("password").(string)
}
if config.Token == "" && config.Username == "" {
return nil, fmt.Errorf("Error configuring provider: either a `token` or `username` must be specified")
}
return config.Client()
}