github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/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.DefaultHeader.Set(terraform.VersionHeader, terraform.VersionString()) 56 client.Token = d.Get("token").(string) 57 58 return client, nil 59 } 60 61 var descriptions map[string]string 62 63 func init() { 64 descriptions = map[string]string{ 65 "address": "The address of the Atlas server. If blank, the public\n" + 66 "server at atlas.hashicorp.com will be used.", 67 68 "token": "The access token for reading artifacts. This is required\n" + 69 "if reading private artifacts.", 70 } 71 }