From bfe492d4077ba2cedca46d9fc4b858d1afa7ed83 Mon Sep 17 00:00:00 2001 From: Jon Perritt Date: Sun, 25 Jan 2015 21:00:57 -0700 Subject: [PATCH] add options for openstack identity v3 --- builtin/providers/openstack/config.go | 22 +++++----- builtin/providers/openstack/provider.go | 56 +++++++++++++++---------- 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/builtin/providers/openstack/config.go b/builtin/providers/openstack/config.go index d877fcd80..215817bdd 100644 --- a/builtin/providers/openstack/config.go +++ b/builtin/providers/openstack/config.go @@ -6,22 +6,30 @@ import ( ) type Config struct { - Region string Username string + UserID string Password string + APIKey string IdentityEndpoint string + TenantID string TenantName string + DomainID string + DomainName string - computeV2Client *gophercloud.ServiceClient - networkingV2Client *gophercloud.ServiceClient + osClient *gophercloud.ProviderClient } func (c *Config) loadAndValidate() error { ao := gophercloud.AuthOptions{ Username: c.Username, + UserID: c.UserID, Password: c.Password, + APIKey: c.APIKey, IdentityEndpoint: c.IdentityEndpoint, + TenantID: c.TenantID, TenantName: c.TenantName, + DomainID: c.DomainID, + DomainName: c.DomainName, } client, err := openstack.AuthenticatedClient(ao) @@ -29,13 +37,7 @@ func (c *Config) loadAndValidate() error { return err } - c.computeV2Client, err = openstack.NewComputeV2(client, gophercloud.EndpointOpts{ - Region: c.Region, - }) - - c.networkingV2Client, err = openstack.NewNetworkV2(client, gophercloud.EndpointOpts{ - Region: c.Region, - }) + c.osClient = client return nil } diff --git a/builtin/providers/openstack/provider.go b/builtin/providers/openstack/provider.go index 764266cd4..8b3e37a58 100644 --- a/builtin/providers/openstack/provider.go +++ b/builtin/providers/openstack/provider.go @@ -15,27 +15,46 @@ func Provider() terraform.ResourceProvider { Type: schema.TypeString, Required: true, DefaultFunc: envDefaultFunc("OS_AUTH_URL"), - Description: descriptions["auth_url"], }, - - "username": &schema.Schema{ + "user_name": &schema.Schema{ Type: schema.TypeString, - Required: true, + Optional: true, DefaultFunc: envDefaultFunc("OS_USERNAME"), - Description: descriptions["username"], }, - + "user_id": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + DefaultFunc: envDefaultFunc("OS_USERID"), + }, + "tenant_id": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + DefaultFunc: envDefaultFunc("OS_TENANT_ID"), + }, "tenant_name": &schema.Schema{ Type: schema.TypeString, Optional: true, DefaultFunc: envDefaultFunc("OS_TENANT_NAME"), }, - "password": &schema.Schema{ Type: schema.TypeString, - Required: true, + Optional: true, DefaultFunc: envDefaultFunc("OS_PASSWORD"), - Description: descriptions["password"], + }, + "api_key": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + DefaultFunc: envDefaultFunc("OS_API_KEY"), + }, + "domain_id": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + DefaultFunc: envDefaultFunc("OS_DOMAIN_ID"), + }, + "domain_name": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + DefaultFunc: envDefaultFunc("OS_DOMAIN_NAME"), }, }, @@ -58,11 +77,15 @@ func Provider() terraform.ResourceProvider { 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), + Username: d.Get("user_name").(string), + UserID: d.Get("user_id").(string), Password: d.Get("password").(string), + APIKey: d.Get("api_key").(string), + TenantID: d.Get("tenant_id").(string), TenantName: d.Get("tenant_name").(string), + DomainID: d.Get("domain_id").(string), + DomainName: d.Get("domain_name").(string), } if err := config.loadAndValidate(); err != nil { @@ -81,14 +104,3 @@ func envDefaultFunc(k string) schema.SchemaDefaultFunc { 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.", - } -}