github.com/keshavdv/terraform@v0.7.0-rc2.0.20160711232630-d69256dcb425/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 DataSourcesMap: map[string]*schema.Resource{ 35 "atlas_artifact": dataSourceAtlasArtifact(), 36 }, 37 38 ResourcesMap: map[string]*schema.Resource{ 39 "atlas_artifact": resourceArtifact(), 40 }, 41 42 ConfigureFunc: providerConfigure, 43 } 44 } 45 46 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 47 var err error 48 client := atlas.DefaultClient() 49 if v := d.Get("address").(string); v != "" { 50 client, err = atlas.NewClient(v) 51 if err != nil { 52 return nil, err 53 } 54 } 55 client.Token = d.Get("token").(string) 56 57 return client, nil 58 } 59 60 var descriptions map[string]string 61 62 func init() { 63 descriptions = map[string]string{ 64 "address": "The address of the Atlas server. If blank, the public\n" + 65 "server at atlas.hashicorp.com will be used.", 66 67 "token": "The access token for reading artifacts. This is required\n" + 68 "if reading private artifacts.", 69 } 70 }