diff --git a/builtin/providers/openstack/config.go b/builtin/providers/openstack/config.go index 903345fb6..f18465538 100644 --- a/builtin/providers/openstack/config.go +++ b/builtin/providers/openstack/config.go @@ -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, @@ -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 +} diff --git a/builtin/providers/openstack/provider.go b/builtin/providers/openstack/provider.go index 2d68d82ec..4a21d69e2 100644 --- a/builtin/providers/openstack/provider.go +++ b/builtin/providers/openstack/provider.go @@ -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{ @@ -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 { diff --git a/website/source/docs/providers/openstack/index.html.markdown b/website/source/docs/providers/openstack/index.html.markdown index 808b71d1e..be918a465 100644 --- a/website/source/docs/providers/openstack/index.html.markdown +++ b/website/source/docs/providers/openstack/index.html.markdown @@ -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