-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprovider.go
78 lines (75 loc) · 2.71 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
package main
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
scalyr "github.com/scalyr/terraform-provider-dataset/scalyr-go"
)
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"region": &schema.Schema{Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SCALYR_REGION", "us"),
Description: "Scalyr Region",
},
"endpoint": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SCALYR_SERVER", nil),
Description: "Scalyr Server",
},
"read_log_token": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SCALYR_READLOG_TOKEN", nil),
Description: "Scalyr ReadLog API Token",
},
"write_log_token": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SCALYR_WRITELOG_TOKEN", nil),
Description: "Scalyr WriteLog API Token",
},
"read_config_token": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SCALYR_READCONFIG_TOKEN", nil),
Description: "Scalyr ReadConfig API Token",
},
"write_config_token": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SCALYR_WRITECONFIG_TOKEN", nil),
Description: "Scalyr WriteConfig API Token",
},
"team": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SCALYR_TEAM", nil),
Description: "Scalyr Team Identifier",
},
},
ResourcesMap: map[string]*schema.Resource{
"dataset_event": resourceEvent(),
"dataset_file": resourceFile(),
},
DataSourcesMap: map[string]*schema.Resource{
"dataset_file": datasourceFile(),
"dataset_query": datasourceQuery(),
"dataset_teams": datasourceTeams(),
"dataset_tokens": datasourceTokens(),
},
ConfigureFunc: providerConfigure,
}
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
region := d.Get("region").(string)
endpoint := d.Get("endpoint").(string)
readLogToken := d.Get("read_log_token").(string)
writeLogToken := d.Get("write_log_token").(string)
readConfigToken := d.Get("read_config_token").(string)
writeConfigToken := d.Get("write_config_token").(string)
tokens := scalyr.ScalyrTokens{ReadLog: readLogToken, WriteLog: writeLogToken, ReadConfig: readConfigToken, WriteConfig: writeConfigToken}
team := d.Get("team").(string)
return scalyr.NewClient(&scalyr.ScalyrConfig{Endpoint: endpoint, Region: region, Team: team, Tokens: tokens})
}