github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/alicloud/provider.go (about) 1 package alicloud 2 3 import ( 4 "github.com/denverdino/aliyungo/common" 5 "github.com/hashicorp/terraform/helper/mutexkv" 6 "github.com/hashicorp/terraform/helper/schema" 7 "github.com/hashicorp/terraform/terraform" 8 ) 9 10 // Provider returns a schema.Provider for alicloud 11 func Provider() terraform.ResourceProvider { 12 return &schema.Provider{ 13 Schema: map[string]*schema.Schema{ 14 "access_key": &schema.Schema{ 15 Type: schema.TypeString, 16 Required: true, 17 DefaultFunc: schema.EnvDefaultFunc("ALICLOUD_ACCESS_KEY", nil), 18 Description: descriptions["access_key"], 19 }, 20 "secret_key": &schema.Schema{ 21 Type: schema.TypeString, 22 Required: true, 23 DefaultFunc: schema.EnvDefaultFunc("ALICLOUD_SECRET_KEY", nil), 24 Description: descriptions["secret_key"], 25 }, 26 "region": &schema.Schema{ 27 Type: schema.TypeString, 28 Required: true, 29 DefaultFunc: schema.EnvDefaultFunc("ALICLOUD_REGION", DEFAULT_REGION), 30 Description: descriptions["region"], 31 }, 32 }, 33 DataSourcesMap: map[string]*schema.Resource{ 34 35 "alicloud_images": dataSourceAlicloudImages(), 36 "alicloud_regions": dataSourceAlicloudRegions(), 37 "alicloud_zones": dataSourceAlicloudZones(), 38 "alicloud_instance_types": dataSourceAlicloudInstanceTypes(), 39 }, 40 ResourcesMap: map[string]*schema.Resource{ 41 "alicloud_instance": resourceAliyunInstance(), 42 "alicloud_disk": resourceAliyunDisk(), 43 "alicloud_disk_attachment": resourceAliyunDiskAttachment(), 44 "alicloud_security_group": resourceAliyunSecurityGroup(), 45 "alicloud_security_group_rule": resourceAliyunSecurityGroupRule(), 46 "alicloud_db_instance": resourceAlicloudDBInstance(), 47 "alicloud_ess_scaling_group": resourceAlicloudEssScalingGroup(), 48 "alicloud_ess_scaling_configuration": resourceAlicloudEssScalingConfiguration(), 49 "alicloud_ess_scaling_rule": resourceAlicloudEssScalingRule(), 50 "alicloud_ess_schedule": resourceAlicloudEssSchedule(), 51 "alicloud_vpc": resourceAliyunVpc(), 52 "alicloud_nat_gateway": resourceAliyunNatGateway(), 53 //both subnet and vswith exists,cause compatible old version, and compatible aws habit. 54 "alicloud_subnet": resourceAliyunSubnet(), 55 "alicloud_vswitch": resourceAliyunSubnet(), 56 "alicloud_route_entry": resourceAliyunRouteEntry(), 57 "alicloud_snat_entry": resourceAliyunSnatEntry(), 58 "alicloud_forward_entry": resourceAliyunForwardEntry(), 59 "alicloud_eip": resourceAliyunEip(), 60 "alicloud_eip_association": resourceAliyunEipAssociation(), 61 "alicloud_slb": resourceAliyunSlb(), 62 "alicloud_slb_attachment": resourceAliyunSlbAttachment(), 63 }, 64 65 ConfigureFunc: providerConfigure, 66 } 67 } 68 69 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 70 config := Config{ 71 AccessKey: d.Get("access_key").(string), 72 SecretKey: d.Get("secret_key").(string), 73 Region: common.Region(d.Get("region").(string)), 74 } 75 76 client, err := config.Client() 77 if err != nil { 78 return nil, err 79 } 80 81 return client, nil 82 } 83 84 // This is a global MutexKV for use within this plugin. 85 var alicloudMutexKV = mutexkv.NewMutexKV() 86 87 var descriptions map[string]string 88 89 func init() { 90 descriptions = map[string]string{ 91 "access_key": "Access key of alicloud", 92 "secret_key": "Secret key of alicloud", 93 "region": "Region of alicloud", 94 } 95 }