-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovider.go
47 lines (37 loc) · 1.04 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
package main
import (
"errors"
"os"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"path": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("KEYSTORE_PATH", ""),
Description: "The path to use for storing bundles.",
},
},
DataSourcesMap: map[string]*schema.Resource{
"keystore_pkcs12_bundle": dataSourceKeystorePkcs12Bundle(),
},
ResourcesMap: map[string]*schema.Resource{
"keystore_pkcs12_bundle": pkcsBundle(),
},
ConfigureFunc: configureProvider,
}
}
type KeystoreConfig struct {
Path string
}
func configureProvider(d *schema.ResourceData) (meta interface{}, err error) {
path := d.Get("path").(string)
if _, err := os.Stat(path); os.IsNotExist(err) {
if err = os.MkdirAll(path, os.ModePerm); err != nil {
return nil, errors.New("path provided to keystore provider does not exist and cannot be created")
}
}
return KeystoreConfig{Path: path}, nil
}