-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovider.go
54 lines (49 loc) · 1.69 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
package main
import (
"context"
"time"
"github.com/bob-cd/terraform-provider/artifact_store"
c "github.com/bob-cd/terraform-provider/common"
"github.com/bob-cd/terraform-provider/pipeline"
"github.com/bob-cd/terraform-provider/resource_provider"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"url": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("BOB_URL", "http://localhost:7777"),
},
"timeout": {
Type: schema.TypeInt,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("BOB_TIMEOUT", 10000),
},
"reconcile_interval": {
Type: schema.TypeInt,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("BOB_RECONCILE_INTERVAL", 1000),
},
"reconcile_retries": {
Type: schema.TypeInt,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("BOB_RECONCILE_RETRIES", 10),
},
},
ResourcesMap: map[string]*schema.Resource{
"bob_resource_provider": resource_provider.Resource(),
"bob_artifact_store": artifact_store.Resource(),
"bob_pipeline": pipeline.Resource(),
},
ConfigureContextFunc: providerConfigure,
}
}
func providerConfigure(ctx context.Context, data *schema.ResourceData) (any, diag.Diagnostics) {
url := data.Get("url").(string)
timeout := time.Duration(data.Get("timeout").(int)) * time.Millisecond
var diags diag.Diagnostics
return c.NewClient(url, timeout, data.Get("reconcile_retries").(int), time.Duration(data.Get("reconcile_interval").(int))*time.Millisecond), diags
}