-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprovider.go
37 lines (34 loc) · 963 Bytes
/
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
package main
import (
"fmt"
"os"
"github.com/bitfield/checkly"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
// Provider makes the provider available to Terraform.
func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"api_key": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("CHECKLY_API_KEY", nil),
},
},
ResourcesMap: map[string]*schema.Resource{
"checkly_check": resourceCheck(),
},
ConfigureFunc: func(r *schema.ResourceData) (interface{}, error) {
client := checkly.NewClient(r.Get("api_key").(string))
debugLog := os.Getenv("CHECKLY_DEBUG_LOG")
if debugLog != "" {
debugFile, err := os.OpenFile(debugLog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o600)
if err != nil {
panic(fmt.Sprintf("can't write to debug log file: %v", err))
}
client.Debug = debugFile
}
return &client, nil
},
}
}