2014-10-29 22:52:36 +01:00
|
|
|
package openstack
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Provider returns a schema.Provider for OpenStack.
|
|
|
|
func Provider() terraform.ResourceProvider {
|
|
|
|
return &schema.Provider{
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
"region": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
2015-01-04 23:26:57 +01:00
|
|
|
DefaultFunc: envDefaultFunc("OS_REGION_NAME"),
|
2014-10-29 22:52:36 +01:00
|
|
|
Description: descriptions["region"],
|
|
|
|
},
|
|
|
|
|
|
|
|
"auth_url": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
DefaultFunc: envDefaultFunc("OS_AUTH_URL"),
|
|
|
|
Description: descriptions["auth_url"],
|
|
|
|
},
|
|
|
|
|
|
|
|
"username": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
DefaultFunc: envDefaultFunc("OS_USERNAME"),
|
|
|
|
Description: descriptions["username"],
|
|
|
|
},
|
|
|
|
|
|
|
|
"tenant_name": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: envDefaultFunc("OS_TENANT_NAME"),
|
|
|
|
//Description: descriptions["tenantname"],
|
|
|
|
},
|
|
|
|
|
|
|
|
"password": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
DefaultFunc: envDefaultFunc("OS_PASSWORD"),
|
|
|
|
Description: descriptions["password"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
2015-01-08 18:47:10 +01:00
|
|
|
"openstack_compute_instance": resourceComputeInstance(),
|
|
|
|
"openstack_compute_keypair": resourceComputeKeypair(),
|
|
|
|
"openstack_compute_secgroup": resourceComputeSecGroup(),
|
|
|
|
"openstack_compute_secgrouprule": resourceComputeSecGroupRule(),
|
2014-10-29 22:52:36 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
ConfigureFunc: configureProvider,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func configureProvider(d *schema.ResourceData) (interface{}, error) {
|
|
|
|
config := Config{
|
|
|
|
Region: d.Get("region").(string),
|
|
|
|
IdentityEndpoint: d.Get("auth_url").(string),
|
|
|
|
Username: d.Get("username").(string),
|
|
|
|
Password: d.Get("password").(string),
|
2015-01-04 23:26:57 +01:00
|
|
|
TenantName: d.Get("tenant_name").(string),
|
2014-10-29 22:52:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := config.loadAndValidate(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &config, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func envDefaultFunc(k string) schema.SchemaDefaultFunc {
|
|
|
|
return func() (interface{}, error) {
|
|
|
|
if v := os.Getenv(k); v != "" {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var descriptions map[string]string
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
descriptions = map[string]string{
|
|
|
|
"region": "The region where OpenStack operations will take place.",
|
|
|
|
"auth_url": "The endpoint against which to authenticate.",
|
|
|
|
"username": "The username with which to authenticate.",
|
|
|
|
"password": "The password with which to authenticate.",
|
|
|
|
}
|
|
|
|
}
|