github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/nomad/provider.go (about) 1 package nomad 2 3 import ( 4 "fmt" 5 6 "github.com/hashicorp/nomad/api" 7 "github.com/hashicorp/terraform/helper/schema" 8 "github.com/hashicorp/terraform/terraform" 9 ) 10 11 func Provider() terraform.ResourceProvider { 12 return &schema.Provider{ 13 Schema: map[string]*schema.Schema{ 14 "address": &schema.Schema{ 15 Type: schema.TypeString, 16 Required: true, 17 DefaultFunc: schema.EnvDefaultFunc("NOMAD_ADDR", nil), 18 Description: "URL of the root of the target Nomad agent.", 19 }, 20 21 "region": &schema.Schema{ 22 Type: schema.TypeString, 23 Optional: true, 24 DefaultFunc: schema.EnvDefaultFunc("NOMAD_REGION", ""), 25 Description: "Region of the target Nomad agent.", 26 }, 27 }, 28 29 ConfigureFunc: providerConfigure, 30 31 ResourcesMap: map[string]*schema.Resource{ 32 "nomad_job": resourceJob(), 33 }, 34 } 35 } 36 37 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 38 config := api.DefaultConfig() 39 config.Address = d.Get("address").(string) 40 config.Region = d.Get("region").(string) 41 42 client, err := api.NewClient(config) 43 if err != nil { 44 return nil, fmt.Errorf("failed to configure Nomad API: %s", err) 45 } 46 47 return client, nil 48 }