Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openstack / Add endpoint type provider configuration #2262

Merged
merged 2 commits into from
Jun 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions builtin/providers/openstack/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package openstack

import (
"crypto/tls"
"fmt"
"net/http"

"github.com/rackspace/gophercloud"
Expand All @@ -19,11 +20,20 @@ type Config struct {
DomainID string
DomainName string
Insecure bool
EndpointType string

osClient *gophercloud.ProviderClient
}

func (c *Config) loadAndValidate() error {

if c.EndpointType != "internal" && c.EndpointType != "internalURL" &&
c.EndpointType != "admin" && c.EndpointType != "adminURL" &&
c.EndpointType != "public" && c.EndpointType != "publicURL" &&
c.EndpointType != "" {
return fmt.Errorf("Invalid endpoint type provided")
}

ao := gophercloud.AuthOptions{
Username: c.Username,
UserID: c.UserID,
Expand Down Expand Up @@ -60,24 +70,38 @@ func (c *Config) loadAndValidate() error {

func (c *Config) blockStorageV1Client(region string) (*gophercloud.ServiceClient, error) {
return openstack.NewBlockStorageV1(c.osClient, gophercloud.EndpointOpts{
Region: region,
Region: region,
Availability: c.getEndpointType(),
})
}

func (c *Config) computeV2Client(region string) (*gophercloud.ServiceClient, error) {
return openstack.NewComputeV2(c.osClient, gophercloud.EndpointOpts{
Region: region,
Region: region,
Availability: c.getEndpointType(),
})
}

func (c *Config) networkingV2Client(region string) (*gophercloud.ServiceClient, error) {
return openstack.NewNetworkV2(c.osClient, gophercloud.EndpointOpts{
Region: region,
Region: region,
Availability: c.getEndpointType(),
})
}

func (c *Config) objectStorageV1Client(region string) (*gophercloud.ServiceClient, error) {
return openstack.NewObjectStorageV1(c.osClient, gophercloud.EndpointOpts{
Region: region,
Region: region,
Availability: c.getEndpointType(),
})
}

func (c *Config) getEndpointType() gophercloud.Availability {
if c.EndpointType == "internal" || c.EndpointType == "internalURL" {
return gophercloud.AvailabilityInternal
}
if c.EndpointType == "admin" || c.EndpointType == "adminURL" {
return gophercloud.AvailabilityAdmin
}
return gophercloud.AvailabilityPublic
}
10 changes: 8 additions & 2 deletions builtin/providers/openstack/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func Provider() terraform.ResourceProvider {
DefaultFunc: envDefaultFunc("OS_PASSWORD"),
},
"api_key": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
DefaultFunc: envDefaultFunc("OS_AUTH_TOKEN"),
},
"domain_id": &schema.Schema{
Expand All @@ -61,6 +61,11 @@ func Provider() terraform.ResourceProvider {
Optional: true,
Default: false,
},
"endpoint_type": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: envDefaultFunc("OS_ENDPOINT_TYPE"),
},
},

ResourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -99,6 +104,7 @@ func configureProvider(d *schema.ResourceData) (interface{}, error) {
DomainID: d.Get("domain_id").(string),
DomainName: d.Get("domain_name").(string),
Insecure: d.Get("insecure").(bool),
EndpointType: d.Get("endpoint_type").(string),
}

if err := config.loadAndValidate(); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions website/source/docs/providers/openstack/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ The following arguments are supported:
* `insecure` - (Optional) Explicitly allow the provider to perform
"insecure" SSL requests. If omitted, default value is `false`

* `endpoint_type` - (Optional) Specify which type of endpoint to use from the
service catalog. It can be set using the OS_ENDPOINT_TYPE environment
variable. If not set, public endpoints is used.

## Testing

In order to run the Acceptance Tests for development, the following environment
Expand Down