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{
|
|
|
|
"auth_url": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
DefaultFunc: envDefaultFunc("OS_AUTH_URL"),
|
|
|
|
},
|
2015-01-26 05:00:57 +01:00
|
|
|
"user_name": &schema.Schema{
|
2014-10-29 22:52:36 +01:00
|
|
|
Type: schema.TypeString,
|
2015-01-26 05:00:57 +01:00
|
|
|
Optional: true,
|
2014-10-29 22:52:36 +01:00
|
|
|
DefaultFunc: envDefaultFunc("OS_USERNAME"),
|
|
|
|
},
|
2015-01-26 05:00:57 +01:00
|
|
|
"user_id": &schema.Schema{
|
2015-01-26 23:45:05 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Default: "",
|
2015-01-26 05:00:57 +01:00
|
|
|
},
|
|
|
|
"tenant_id": &schema.Schema{
|
2015-01-26 23:45:05 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Default: "",
|
2015-01-26 05:00:57 +01:00
|
|
|
},
|
2014-10-29 22:52:36 +01:00
|
|
|
"tenant_name": &schema.Schema{
|
2015-01-27 18:19:11 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: envDefaultFunc("OS_TENANT_NAME"),
|
2014-10-29 22:52:36 +01:00
|
|
|
},
|
|
|
|
"password": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
2015-01-26 05:00:57 +01:00
|
|
|
Optional: true,
|
2014-10-29 22:52:36 +01:00
|
|
|
DefaultFunc: envDefaultFunc("OS_PASSWORD"),
|
2015-01-26 05:00:57 +01:00
|
|
|
},
|
|
|
|
"api_key": &schema.Schema{
|
2015-01-26 23:45:05 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Default: "",
|
2015-01-26 05:00:57 +01:00
|
|
|
},
|
|
|
|
"domain_id": &schema.Schema{
|
2015-01-26 23:45:05 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Default: "",
|
2015-01-26 05:00:57 +01:00
|
|
|
},
|
|
|
|
"domain_name": &schema.Schema{
|
2015-01-26 23:45:05 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Default: "",
|
2014-10-29 22:52:36 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
2015-02-01 08:34:37 +01:00
|
|
|
"openstack_blockstorage_volume_v1": resourceBlockStorageVolumeV1(),
|
2015-02-01 04:51:50 +01:00
|
|
|
"openstack_compute_instance_v2": resourceComputeInstanceV2(),
|
|
|
|
"openstack_compute_keypair_v2": resourceComputeKeypairV2(),
|
|
|
|
"openstack_compute_secgroup_v2": resourceComputeSecGroupV2(),
|
|
|
|
"openstack_lb_monitor_v1": resourceLBMonitorV1(),
|
|
|
|
"openstack_lb_pool_v1": resourceLBPoolV1(),
|
|
|
|
"openstack_lb_vip_v1": resourceLBVipV1(),
|
|
|
|
"openstack_networking_network_v2": resourceNetworkingNetworkV2(),
|
|
|
|
"openstack_networking_subnet_v2": resourceNetworkingSubnetV2(),
|
|
|
|
"openstack_objectstorage_container_v1": resourceObjectStorageContainerV1(),
|
2014-10-29 22:52:36 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
ConfigureFunc: configureProvider,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func configureProvider(d *schema.ResourceData) (interface{}, error) {
|
|
|
|
config := Config{
|
|
|
|
IdentityEndpoint: d.Get("auth_url").(string),
|
2015-01-26 05:00:57 +01:00
|
|
|
Username: d.Get("user_name").(string),
|
|
|
|
UserID: d.Get("user_id").(string),
|
2014-10-29 22:52:36 +01:00
|
|
|
Password: d.Get("password").(string),
|
2015-01-26 05:00:57 +01:00
|
|
|
APIKey: d.Get("api_key").(string),
|
|
|
|
TenantID: d.Get("tenant_id").(string),
|
2015-01-04 23:26:57 +01:00
|
|
|
TenantName: d.Get("tenant_name").(string),
|
2015-01-26 05:00:57 +01:00
|
|
|
DomainID: d.Get("domain_id").(string),
|
|
|
|
DomainName: d.Get("domain_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
|
|
|
|
}
|
|
|
|
}
|