forked from mrolla/terraform-provider-circleci
/
provider.go
59 lines (55 loc) · 1.96 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
package circleci
import (
"github.com/SectorLabs/terraform-provider-circleci/circleci/client"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"organization": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("CIRCLECI_ORGANIZATION", nil),
Description: "The CircleCI organization.",
},
"api_token": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("CIRCLECI_TOKEN", nil),
Description: "The token key for API operations.",
},
"vcs_type": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("CIRCLECI_VCS_TYPE", "github"),
Description: "The VCS type for the organization.",
},
"url": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("CIRCLECI_URL", "https://circleci.com/api/v2/"),
Description: "The URL of the Circle CI API (v2)",
},
},
ResourcesMap: map[string]*schema.Resource{
"circleci_environment_variable": resourceCircleCIEnvironmentVariable(),
"circleci_context": resourceCircleCIContext(),
"circleci_context_environment_variable": resourceCircleCIContextEnvironmentVariable(),
"circleci_checkout_key": resourceCircleCICheckoutKey(),
},
DataSourcesMap: map[string]*schema.Resource{
"circleci_project": dataSourceCircleCIProject(),
"circleci_context": dataSourceCircleCIContext(),
},
ConfigureFunc: providerConfigure,
}
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
return client.New(client.Config{
URL: d.Get("url").(string),
Token: d.Get("api_token").(string),
Organization: d.Get("organization").(string),
VCS: d.Get("vcs_type").(string),
})
}