2014-10-29 22:52:36 +01:00
|
|
|
package openstack
|
|
|
|
|
|
|
|
import (
|
2016-04-19 23:26:09 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/mutexkv"
|
2014-10-29 22:52:36 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
2016-04-19 23:26:09 +02:00
|
|
|
// This is a global MutexKV for use within this plugin.
|
|
|
|
var osMutexKV = mutexkv.NewMutexKV()
|
|
|
|
|
2014-10-29 22:52:36 +01:00
|
|
|
// 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,
|
2016-04-08 23:28:54 +02:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("OS_AUTH_URL", nil),
|
2016-11-01 14:16:39 +01:00
|
|
|
Description: descriptions["auth_url"],
|
2014-10-29 22:52:36 +01:00
|
|
|
},
|
2016-11-01 14:16:39 +01:00
|
|
|
|
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,
|
2016-04-08 06:07:42 +02:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("OS_USERNAME", ""),
|
2016-11-01 14:16:39 +01:00
|
|
|
Description: descriptions["user_name"],
|
2014-10-29 22:52:36 +01:00
|
|
|
},
|
2016-11-01 14:16:39 +01:00
|
|
|
|
2015-01-26 05:00:57 +01:00
|
|
|
"user_id": &schema.Schema{
|
2016-11-01 14:16:39 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("OS_USER_ID", ""),
|
|
|
|
Description: descriptions["user_name"],
|
2015-01-26 05:00:57 +01:00
|
|
|
},
|
2016-11-01 14:16:39 +01:00
|
|
|
|
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,
|
2016-11-01 14:16:39 +01:00
|
|
|
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
|
|
|
|
"OS_TENANT_ID",
|
|
|
|
"OS_PROJECT_ID",
|
|
|
|
}, ""),
|
|
|
|
Description: descriptions["tenant_id"],
|
2015-01-26 05:00:57 +01:00
|
|
|
},
|
2016-11-01 14:16:39 +01:00
|
|
|
|
2014-10-29 22:52:36 +01:00
|
|
|
"tenant_name": &schema.Schema{
|
2016-11-01 14:16:39 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
|
|
|
|
"OS_TENANT_NAME",
|
|
|
|
"OS_PROJECT_NAME",
|
|
|
|
}, ""),
|
|
|
|
Description: descriptions["tenant_name"],
|
2014-10-29 22:52:36 +01:00
|
|
|
},
|
2016-11-01 14:16:39 +01:00
|
|
|
|
2014-10-29 22:52:36 +01:00
|
|
|
"password": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
2015-01-26 05:00:57 +01:00
|
|
|
Optional: true,
|
2016-11-01 14:16:39 +01:00
|
|
|
Sensitive: true,
|
2016-04-08 06:07:42 +02:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("OS_PASSWORD", ""),
|
2016-11-01 14:16:39 +01:00
|
|
|
Description: descriptions["password"],
|
2015-01-26 05:00:57 +01:00
|
|
|
},
|
2016-11-01 14:16:39 +01:00
|
|
|
|
2016-04-08 06:07:42 +02:00
|
|
|
"token": &schema.Schema{
|
2015-06-07 23:01:00 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
2016-04-08 23:28:54 +02:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("OS_AUTH_TOKEN", ""),
|
2016-11-01 14:16:39 +01:00
|
|
|
Description: descriptions["token"],
|
2015-01-26 05:00:57 +01:00
|
|
|
},
|
2016-11-01 14:16:39 +01:00
|
|
|
|
2015-01-26 05:00:57 +01:00
|
|
|
"domain_id": &schema.Schema{
|
2016-11-01 14:16:39 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
|
|
|
|
"OS_USER_DOMAIN_ID",
|
|
|
|
"OS_PROJECT_DOMAIN_ID",
|
|
|
|
"OS_DOMAIN_ID",
|
|
|
|
}, ""),
|
|
|
|
Description: descriptions["domain_id"],
|
2015-01-26 05:00:57 +01:00
|
|
|
},
|
2016-11-01 14:16:39 +01:00
|
|
|
|
2015-01-26 05:00:57 +01:00
|
|
|
"domain_name": &schema.Schema{
|
2016-11-01 14:16:39 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
|
|
|
|
"OS_USER_DOMAIN_NAME",
|
|
|
|
"OS_PROJECT_DOMAIN_NAME",
|
|
|
|
"OS_DOMAIN_NAME",
|
|
|
|
"OS_DEFAULT_DOMAIN",
|
|
|
|
}, ""),
|
|
|
|
Description: descriptions["domain_name"],
|
2014-10-29 22:52:36 +01:00
|
|
|
},
|
2016-11-01 14:16:39 +01:00
|
|
|
|
2015-04-15 14:58:01 +02:00
|
|
|
"insecure": &schema.Schema{
|
2016-11-01 14:16:39 +01:00
|
|
|
Type: schema.TypeBool,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("OS_INSECURE", ""),
|
|
|
|
Description: descriptions["insecure"],
|
2015-04-15 14:58:01 +02:00
|
|
|
},
|
2016-11-01 14:16:39 +01:00
|
|
|
|
2015-06-07 22:57:55 +02:00
|
|
|
"endpoint_type": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
2016-04-08 23:28:54 +02:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("OS_ENDPOINT_TYPE", ""),
|
2015-06-07 22:57:55 +02:00
|
|
|
},
|
2016-11-01 14:16:39 +01:00
|
|
|
|
2016-02-12 07:56:11 +01:00
|
|
|
"cacert_file": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
2016-04-08 23:28:54 +02:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("OS_CACERT", ""),
|
2016-11-01 14:16:39 +01:00
|
|
|
Description: descriptions["cacert_file"],
|
2016-02-12 07:56:11 +01:00
|
|
|
},
|
2016-11-01 14:16:39 +01:00
|
|
|
|
2016-04-21 11:39:49 +02:00
|
|
|
"cert": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("OS_CERT", ""),
|
2016-11-01 14:16:39 +01:00
|
|
|
Description: descriptions["cert"],
|
2016-04-21 11:39:49 +02:00
|
|
|
},
|
2016-11-01 14:16:39 +01:00
|
|
|
|
2016-04-21 11:39:49 +02:00
|
|
|
"key": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("OS_KEY", ""),
|
2016-11-01 14:16:39 +01:00
|
|
|
Description: descriptions["key"],
|
2016-04-21 11:39:49 +02:00
|
|
|
},
|
2016-11-08 06:30:55 +01:00
|
|
|
|
|
|
|
"swauth": &schema.Schema{
|
|
|
|
Type: schema.TypeBool,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("OS_SWAUTH", ""),
|
|
|
|
Description: descriptions["swauth"],
|
|
|
|
},
|
2014-10-29 22:52:36 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
2015-02-09 23:37:58 +01:00
|
|
|
"openstack_blockstorage_volume_v1": resourceBlockStorageVolumeV1(),
|
2016-05-16 22:37:58 +02:00
|
|
|
"openstack_blockstorage_volume_v2": resourceBlockStorageVolumeV2(),
|
2016-11-20 22:15:07 +01:00
|
|
|
"openstack_blockstorage_volume_attach_v2": resourceBlockStorageVolumeAttachV2(),
|
2015-02-09 23:37:58 +01:00
|
|
|
"openstack_compute_instance_v2": resourceComputeInstanceV2(),
|
|
|
|
"openstack_compute_keypair_v2": resourceComputeKeypairV2(),
|
|
|
|
"openstack_compute_secgroup_v2": resourceComputeSecGroupV2(),
|
2015-05-05 18:38:15 +02:00
|
|
|
"openstack_compute_servergroup_v2": resourceComputeServerGroupV2(),
|
2015-02-13 21:59:41 +01:00
|
|
|
"openstack_compute_floatingip_v2": resourceComputeFloatingIPV2(),
|
2016-11-10 17:00:37 +01:00
|
|
|
"openstack_compute_volume_attach_v2": resourceComputeVolumeAttachV2(),
|
2015-02-19 22:55:54 +01:00
|
|
|
"openstack_fw_firewall_v1": resourceFWFirewallV1(),
|
|
|
|
"openstack_fw_policy_v1": resourceFWPolicyV1(),
|
|
|
|
"openstack_fw_rule_v1": resourceFWRuleV1(),
|
2015-12-17 08:20:36 +01:00
|
|
|
"openstack_lb_member_v1": resourceLBMemberV1(),
|
2015-02-09 23:37:58 +01:00
|
|
|
"openstack_lb_monitor_v1": resourceLBMonitorV1(),
|
|
|
|
"openstack_lb_pool_v1": resourceLBPoolV1(),
|
|
|
|
"openstack_lb_vip_v1": resourceLBVipV1(),
|
2016-06-09 22:19:52 +02:00
|
|
|
"openstack_lb_loadbalancer_v2": resourceLoadBalancerV2(),
|
|
|
|
"openstack_lb_listener_v2": resourceListenerV2(),
|
|
|
|
"openstack_lb_pool_v2": resourcePoolV2(),
|
|
|
|
"openstack_lb_member_v2": resourceMemberV2(),
|
|
|
|
"openstack_lb_monitor_v2": resourceMonitorV2(),
|
2015-02-09 23:37:58 +01:00
|
|
|
"openstack_networking_network_v2": resourceNetworkingNetworkV2(),
|
|
|
|
"openstack_networking_subnet_v2": resourceNetworkingSubnetV2(),
|
|
|
|
"openstack_networking_floatingip_v2": resourceNetworkingFloatingIPV2(),
|
2015-05-03 16:20:47 +02:00
|
|
|
"openstack_networking_port_v2": resourceNetworkingPortV2(),
|
2015-02-09 23:37:58 +01:00
|
|
|
"openstack_networking_router_v2": resourceNetworkingRouterV2(),
|
|
|
|
"openstack_networking_router_interface_v2": resourceNetworkingRouterInterfaceV2(),
|
2016-04-19 23:26:09 +02:00
|
|
|
"openstack_networking_router_route_v2": resourceNetworkingRouterRouteV2(),
|
2016-05-03 10:12:26 +02:00
|
|
|
"openstack_networking_secgroup_v2": resourceNetworkingSecGroupV2(),
|
|
|
|
"openstack_networking_secgroup_rule_v2": resourceNetworkingSecGroupRuleV2(),
|
2015-02-09 23:37:58 +01:00
|
|
|
"openstack_objectstorage_container_v1": resourceObjectStorageContainerV1(),
|
2014-10-29 22:52:36 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
ConfigureFunc: configureProvider,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-01 14:16:39 +01:00
|
|
|
var descriptions map[string]string
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
descriptions = map[string]string{
|
|
|
|
"auth_url": "The Identity authentication URL.",
|
|
|
|
|
|
|
|
"user_name": "Username to login with.",
|
|
|
|
|
|
|
|
"user_id": "User ID to login with.",
|
|
|
|
|
|
|
|
"tenant_id": "The ID of the Tenant (Identity v2) or Project (Identity v3)\n" +
|
|
|
|
"to login with.",
|
|
|
|
|
|
|
|
"tenant_name": "The name of the Tenant (Identity v2) or Project (Identity v3)\n" +
|
|
|
|
"to login with.",
|
|
|
|
|
|
|
|
"password": "Password to login with.",
|
|
|
|
|
|
|
|
"token": "Authentication token to use as an alternative to username/password.",
|
|
|
|
|
|
|
|
"domain_id": "The ID of the Domain to scope to (Identity v3).",
|
|
|
|
|
|
|
|
"domain_name": "The name of the Domain to scope to (Identity v3).",
|
|
|
|
|
|
|
|
"insecure": "Trust self-signed certificates.",
|
|
|
|
|
|
|
|
"cacert_file": "A Custom CA certificate.",
|
|
|
|
|
|
|
|
"endpoint_type": "The catalog endpoint type to use.",
|
|
|
|
|
|
|
|
"cert": "A client certificate to authenticate with.",
|
|
|
|
|
|
|
|
"key": "A client private key to authenticate with.",
|
2016-11-08 06:30:55 +01:00
|
|
|
|
|
|
|
"swauth": "Use Swift's authentication system instead of Keystone. Only used for\n" +
|
|
|
|
"interaction with Swift.",
|
2016-11-01 14:16:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-29 22:52:36 +01:00
|
|
|
func configureProvider(d *schema.ResourceData) (interface{}, error) {
|
|
|
|
config := Config{
|
2016-11-01 14:16:39 +01:00
|
|
|
CACertFile: d.Get("cacert_file").(string),
|
|
|
|
ClientCertFile: d.Get("cert").(string),
|
|
|
|
ClientKeyFile: d.Get("key").(string),
|
|
|
|
DomainID: d.Get("domain_id").(string),
|
|
|
|
DomainName: d.Get("domain_name").(string),
|
|
|
|
EndpointType: d.Get("endpoint_type").(string),
|
2014-10-29 22:52:36 +01:00
|
|
|
IdentityEndpoint: d.Get("auth_url").(string),
|
2016-11-01 14:16:39 +01:00
|
|
|
Insecure: d.Get("insecure").(bool),
|
2014-10-29 22:52:36 +01:00
|
|
|
Password: d.Get("password").(string),
|
2016-11-08 06:30:55 +01:00
|
|
|
Swauth: d.Get("swauth").(bool),
|
2016-04-08 06:07:42 +02:00
|
|
|
Token: d.Get("token").(string),
|
2015-01-26 05:00:57 +01:00
|
|
|
TenantID: d.Get("tenant_id").(string),
|
2015-01-04 23:26:57 +01:00
|
|
|
TenantName: d.Get("tenant_name").(string),
|
2016-11-01 14:16:39 +01:00
|
|
|
Username: d.Get("user_name").(string),
|
|
|
|
UserID: d.Get("user_id").(string),
|
2014-10-29 22:52:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := config.loadAndValidate(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &config, nil
|
|
|
|
}
|