Merge pull request #2262 from ggiamarchi/openstack/endpoint_type
Openstack / Add endpoint type provider configuration
This commit is contained in:
commit
27acb45522
|
@ -2,6 +2,7 @@ package openstack
|
|||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/rackspace/gophercloud"
|
||||
|
@ -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,
|
||||
|
@ -61,23 +71,37 @@ func (c *Config) loadAndValidate() error {
|
|||
func (c *Config) blockStorageV1Client(region string) (*gophercloud.ServiceClient, error) {
|
||||
return openstack.NewBlockStorageV1(c.osClient, gophercloud.EndpointOpts{
|
||||
Region: region,
|
||||
Availability: c.getEndpointType(),
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Config) computeV2Client(region string) (*gophercloud.ServiceClient, error) {
|
||||
return openstack.NewComputeV2(c.osClient, gophercloud.EndpointOpts{
|
||||
Region: region,
|
||||
Availability: c.getEndpointType(),
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Config) networkingV2Client(region string) (*gophercloud.ServiceClient, error) {
|
||||
return openstack.NewNetworkV2(c.osClient, gophercloud.EndpointOpts{
|
||||
Region: region,
|
||||
Availability: c.getEndpointType(),
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Config) objectStorageV1Client(region string) (*gophercloud.ServiceClient, error) {
|
||||
return openstack.NewObjectStorageV1(c.osClient, gophercloud.EndpointOpts{
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue