github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/atlas/provider.go (about) 1 package atlas 2 3 import ( 4 "github.com/hashicorp/atlas-go/v1" 5 "github.com/hashicorp/terraform/helper/schema" 6 "github.com/hashicorp/terraform/terraform" 7 ) 8 9 const ( 10 // defaultAtlasServer is the default endpoint for Atlas if 11 // none is specified. 12 defaultAtlasServer = "https://atlas.hashicorp.com" 13 ) 14 15 // Provider returns a terraform.ResourceProvider. 16 func Provider() terraform.ResourceProvider { 17 return &schema.Provider{ 18 Schema: map[string]*schema.Schema{ 19 "token": &schema.Schema{ 20 Type: schema.TypeString, 21 Required: true, 22 DefaultFunc: schema.EnvDefaultFunc("ATLAS_TOKEN", nil), 23 Description: descriptions["token"], 24 }, 25 26 "address": &schema.Schema{ 27 Type: schema.TypeString, 28 Optional: true, 29 DefaultFunc: schema.EnvDefaultFunc("ATLAS_ADDRESS", defaultAtlasServer), 30 Description: descriptions["address"], 31 }, 32 }, 33 34 ResourcesMap: map[string]*schema.Resource{ 35 "atlas_artifact": resourceArtifact(), 36 }, 37 38 ConfigureFunc: providerConfigure, 39 } 40 } 41 42 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 43 var err error 44 client := atlas.DefaultClient() 45 if v := d.Get("address").(string); v != "" { 46 client, err = atlas.NewClient(v) 47 if err != nil { 48 return nil, err 49 } 50 } 51 client.Token = d.Get("token").(string) 52 53 return client, nil 54 } 55 56 var descriptions map[string]string 57 58 func init() { 59 descriptions = map[string]string{ 60 "address": "The address of the Atlas server. If blank, the public\n" + 61 "server at atlas.hashicorp.com will be used.", 62 63 "token": "The access token for reading artifacts. This is required\n" + 64 "if reading private artifacts.", 65 } 66 }