forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 7
/
provider.go
49 lines (40 loc) · 1.12 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
package nomad
import (
"fmt"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"address": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("NOMAD_ADDR", nil),
Description: "URL of the root of the target Nomad agent.",
},
"region": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("NOMAD_REGION", ""),
Description: "Region of the target Nomad agent.",
},
},
ConfigureFunc: providerConfigure,
ResourcesMap: map[string]*schema.Resource{
"nomad_job": resourceJob(),
},
}
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := &api.Config{
Address: d.Get("address").(string),
Region: d.Get("region").(string),
}
client, err := api.NewClient(config)
if err != nil {
return nil, fmt.Errorf("failed to configure Nomad API: %s", err)
}
return client, nil
}