github.com/chalford/terraform@v0.3.7-0.20150113080010-a78c69a8c81f/builtin/providers/cloudstack/provider.go (about) 1 package cloudstack 2 3 import ( 4 "os" 5 6 "github.com/hashicorp/terraform/helper/schema" 7 "github.com/hashicorp/terraform/terraform" 8 ) 9 10 // Provider returns a terraform.ResourceProvider. 11 func Provider() terraform.ResourceProvider { 12 return &schema.Provider{ 13 Schema: map[string]*schema.Schema{ 14 "api_url": &schema.Schema{ 15 Type: schema.TypeString, 16 Required: true, 17 DefaultFunc: envDefaultFunc("CLOUDSTACK_API_URL", nil), 18 }, 19 20 "api_key": &schema.Schema{ 21 Type: schema.TypeString, 22 Required: true, 23 DefaultFunc: envDefaultFunc("CLOUDSTACK_API_KEY", nil), 24 }, 25 26 "secret_key": &schema.Schema{ 27 Type: schema.TypeString, 28 Required: true, 29 DefaultFunc: envDefaultFunc("CLOUDSTACK_SECRET_KEY", nil), 30 }, 31 32 "timeout": &schema.Schema{ 33 Type: schema.TypeInt, 34 Required: true, 35 DefaultFunc: envDefaultFunc("CLOUDSTACK_TIMEOUT", 180), 36 }, 37 }, 38 39 ResourcesMap: map[string]*schema.Resource{ 40 "cloudstack_disk": resourceCloudStackDisk(), 41 "cloudstack_firewall": resourceCloudStackFirewall(), 42 "cloudstack_instance": resourceCloudStackInstance(), 43 "cloudstack_ipaddress": resourceCloudStackIPAddress(), 44 "cloudstack_network": resourceCloudStackNetwork(), 45 "cloudstack_network_acl": resourceCloudStackNetworkACL(), 46 "cloudstack_network_acl_rule": resourceCloudStackNetworkACLRule(), 47 "cloudstack_nic": resourceCloudStackNIC(), 48 "cloudstack_port_forward": resourceCloudStackPortForward(), 49 "cloudstack_vpc": resourceCloudStackVPC(), 50 }, 51 52 ConfigureFunc: providerConfigure, 53 } 54 } 55 56 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 57 config := Config{ 58 ApiURL: d.Get("api_url").(string), 59 ApiKey: d.Get("api_key").(string), 60 SecretKey: d.Get("secret_key").(string), 61 Timeout: int64(d.Get("timeout").(int)), 62 } 63 64 return config.NewClient() 65 } 66 67 func envDefaultFunc(k string, dv interface{}) schema.SchemaDefaultFunc { 68 return func() (interface{}, error) { 69 if v := os.Getenv(k); v != "" { 70 return v, nil 71 } 72 73 return dv, nil 74 } 75 }