github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/ns1/provider.go (about) 1 package ns1 2 3 import ( 4 "crypto/tls" 5 "net/http" 6 7 "github.com/hashicorp/terraform/helper/schema" 8 "github.com/hashicorp/terraform/terraform" 9 10 ns1 "gopkg.in/ns1/ns1-go.v2/rest" 11 ) 12 13 // Provider returns a terraform.ResourceProvider. 14 func Provider() terraform.ResourceProvider { 15 return &schema.Provider{ 16 Schema: map[string]*schema.Schema{ 17 "apikey": &schema.Schema{ 18 Type: schema.TypeString, 19 Required: true, 20 DefaultFunc: schema.EnvDefaultFunc("NS1_APIKEY", nil), 21 Description: descriptions["api_key"], 22 }, 23 "endpoint": &schema.Schema{ 24 Type: schema.TypeString, 25 Optional: true, 26 DefaultFunc: schema.EnvDefaultFunc("NS1_ENDPOINT", nil), 27 Description: descriptions["endpoint"], 28 }, 29 "ignore_ssl": &schema.Schema{ 30 Type: schema.TypeBool, 31 Optional: true, 32 DefaultFunc: schema.EnvDefaultFunc("NS1_IGNORE_SSL", nil), 33 Description: descriptions["ignore_ssl"], 34 }, 35 }, 36 ResourcesMap: map[string]*schema.Resource{ 37 "ns1_zone": zoneResource(), 38 "ns1_record": recordResource(), 39 "ns1_datasource": dataSourceResource(), 40 "ns1_datafeed": dataFeedResource(), 41 "ns1_monitoringjob": monitoringJobResource(), 42 "ns1_notifylist": notifyListResource(), 43 "ns1_user": userResource(), 44 "ns1_apikey": apikeyResource(), 45 "ns1_team": teamResource(), 46 }, 47 ConfigureFunc: ns1Configure, 48 } 49 } 50 51 func ns1Configure(d *schema.ResourceData) (interface{}, error) { 52 httpClient := &http.Client{} 53 decos := []func(*ns1.Client){} 54 decos = append(decos, ns1.SetAPIKey(d.Get("apikey").(string))) 55 if v, ok := d.GetOk("endpoint"); ok { 56 decos = append(decos, ns1.SetEndpoint(v.(string))) 57 } 58 if _, ok := d.GetOk("ignore_ssl"); ok { 59 tr := &http.Transport{ 60 TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 61 } 62 httpClient.Transport = tr 63 } 64 65 n := ns1.NewClient(httpClient, decos...) 66 n.RateLimitStrategySleep() 67 return n, nil 68 } 69 70 var descriptions map[string]string 71 72 func init() { 73 descriptions = map[string]string{ 74 "api_key": "The ns1 API key, this is required", 75 } 76 }