-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.go
69 lines (63 loc) · 1.99 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
package kibana
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
gk "github.com/renato0307/go-kibana/kibana"
)
// Provider - Kibana Terraform provider definition
func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"host": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("KIBANA_URL", nil),
},
"username": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("KIBANA_USERNAME", nil),
},
"password": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
DefaultFunc: schema.EnvDefaultFunc("KIBANA_PASSWORD", nil),
},
"space": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
DefaultFunc: schema.EnvDefaultFunc("KIBANA_SPACE", nil),
},
},
ResourcesMap: map[string]*schema.Resource{
"kibana_actions_connector": resourceActionsConnector(),
"kibana_alerting_rule": resourceAlertingRule(),
},
// DataSourcesMap: map[string]*schema.Resource{
// "hashicups_coffees": dataSourceCoffees(),
// "hashicups_ingredients": dataSourceIngredients(),
// "hashicups_order": dataSourceOrder(),
// },
ConfigureContextFunc: providerConfigure,
}
}
func providerConfigure(_ context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
username := d.Get("username").(string)
password := d.Get("password").(string)
space := d.Get("space").(string)
host := d.Get("host").(string)
var diags diag.Diagnostics // Warning or errors can be collected in a slice type
c, err := gk.NewClient(&host, &username, &password, &space)
if err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "Unable to create Kibana client",
Detail: "Unable to create Kibana client with basic authentication",
})
return nil, diags
}
return c, diags
}