Initial import
This commit is contained in:
29
provider/provider.go
Normal file
29
provider/provider.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/hcl/v2"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
// Name is a unique identifier for the provider.
|
||||
Name string
|
||||
|
||||
// Init is called once to initialize the provider from the matching configuration block.
|
||||
Init func(hcl.Body) error
|
||||
}
|
||||
|
||||
var providerConfigs = make(map[string]*Config)
|
||||
|
||||
func Init(name string, body hcl.Body) error {
|
||||
p, ok := providerConfigs[name]
|
||||
if ok {
|
||||
return p.Init(body)
|
||||
}
|
||||
return fmt.Errorf("provider: no %q provider available", name)
|
||||
}
|
||||
|
||||
func Register(provider *Config) {
|
||||
providerConfigs[provider.Name] = provider
|
||||
}
|
Reference in New Issue
Block a user