-
Notifications
You must be signed in to change notification settings - Fork 3
/
provider.go
80 lines (75 loc) · 3.59 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
80
package main
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
_ "net/http"
)
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"elasticsearch_url": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ELASTICSEARCH_URL", nil),
Description: "Elasticsearch URL",
},
"elasticsearch_username": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ELASTICSEARCH_USERNAME", nil),
Description: "Elasticsearch Username",
},
"elasticsearch_password": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("ELASTICSEARCH_PASSWORD", nil),
Description: "Elasticsearch Password",
},
"kibana_url": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("KIBANA_URL", nil),
Description: "Elasticsearch URL",
},
"kibana_username": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("KIBANA_USERNAME", nil),
Description: "Elasticsearch Username",
},
"kibana_password": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("KIBANA_PASSWORD", nil),
Description: "Elasticsearch Password",
},
},
ResourcesMap: map[string]*schema.Resource{
"elastic_kibana_space": resourceKibanaSpace(),
"elastic_kibana_canvas": resourceKibanaCanvas(),
"elastic_kibana_saved_object": resourceKibanaSavedObject(),
"elastic_kibana_saved_object_content": resourceKibanaSavedObjectContent(),
"elastic_elasticsearch_index_data": resourceElasticsearchIndexData(),
"elastic_elasticsearch_watcher": resourceElasticsearchWatcher(),
},
ConfigureFunc: providerConfigure,
}
}
type ElasticInfo struct {
kibanaUrl string
kibanaUsername string
kibanaPassword string
elasticsearchUrl string
elasticsearchUsername string
elasticsearchPassword string
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
url := d.Get("kibana_url").(string)
kibanaUsername := d.Get("kibana_username").(string)
kibanaPassword := d.Get("kibana_password").(string)
elasticsearchUsername := d.Get("elasticsearch_username").(string)
elasticsearchPassword := d.Get("elasticsearch_password").(string)
esUrl := d.Get("elasticsearch_url").(string)
elasticInfo := &ElasticInfo{kibanaUrl: url, elasticsearchUrl: esUrl, kibanaUsername:kibanaUsername, kibanaPassword:kibanaPassword, elasticsearchUsername:elasticsearchUsername, elasticsearchPassword:elasticsearchPassword }
return elasticInfo, nil
}