Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
86 lines (70 sloc) 1.64 KB
package qcloud
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"os"
)
const (
DEFAULT_REGION = "gz"
)
func Provider() terraform.ResourceProvider{
return &schema.Provider{
Schema: map[string]*schema.Schema{
"secret_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: descriptions["secret_id"],
},
"secret_key": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: descriptions["secret_key"],
},
"region": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: descriptions["region"],
},
},
ResourcesMap: map[string]*schema.Resource{
"qcloud_clb": resourceQcloudClb(),
"qcloud_clb_listener": resourceQcloudClbListener(),
},
ConfigureFunc: providerConfigure,
}
}
func providerConfigure(d *schema.ResourceData) (meta interface{}, err error) {
secretid, ok := d.GetOk("secret_id")
if !ok {
secretid = os.Getenv("QCLOUD_SECRETID")
}
secretkey, ok := d.GetOk("secret_key")
if !ok {
secretkey = os.Getenv("QCLOUD_SECRETKEY")
}
region, ok := d.GetOk("region")
if !ok{
region = os.Getenv("QCLOUD_REGION")
if region == "" {
region = DEFAULT_REGION
}
}
config := Config{
SecretId: secretid.(string),
SecretKey: secretkey.(string),
Region: region.(string),
}
client ,err := config.Client()
if err != nil {
return nil, err
}
return client, nil
}
var descriptions map[string]string
func init() {
descriptions = map[string]string{
"secret_id": "SecretId of qcloud.",
"secret_key": "SecretKey of qcloud.",
"region": "Region of qcloud.",
}
}
You can’t perform that action at this time.