github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/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 "ca_file": &schema.Schema{ 28 Type: schema.TypeString, 29 Optional: true, 30 DefaultFunc: schema.EnvDefaultFunc("NOMAD_CACERT", ""), 31 Description: "A path to a PEM-encoded certificate authority used to verify the remote agent's certificate.", 32 }, 33 "cert_file": &schema.Schema{ 34 Type: schema.TypeString, 35 Optional: true, 36 DefaultFunc: schema.EnvDefaultFunc("NOMAD_CLIENT_CERT", ""), 37 Description: "A path to a PEM-encoded certificate provided to the remote agent; requires use of key_file.", 38 }, 39 "key_file": &schema.Schema{ 40 Type: schema.TypeString, 41 Optional: true, 42 DefaultFunc: schema.EnvDefaultFunc("NOMAD_CLIENT_KEY", ""), 43 Description: "A path to a PEM-encoded private key, required if cert_file is specified.", 44 }, 45 }, 46 47 ConfigureFunc: providerConfigure, 48 49 ResourcesMap: map[string]*schema.Resource{ 50 "nomad_job": resourceJob(), 51 }, 52 } 53 } 54 55 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 56 config := api.DefaultConfig() 57 config.Address = d.Get("address").(string) 58 config.Region = d.Get("region").(string) 59 config.TLSConfig.CACert = d.Get("ca_file").(string) 60 config.TLSConfig.ClientCert = d.Get("cert_file").(string) 61 config.TLSConfig.ClientKey = d.Get("key_file").(string) 62 63 client, err := api.NewClient(config) 64 if err != nil { 65 return nil, fmt.Errorf("failed to configure Nomad API: %s", err) 66 } 67 68 return client, nil 69 }