Skip to content

Commit 74189c5

Browse files
committed
provider/openstack: Add Swauth/Swift Authentication
This commit adds the ability to authenticate with Swauth/Swift. This can be used in Swift-only environments that do not have a Keystone service for authentication.
1 parent f0a5dea commit 74189c5

4 files changed

Lines changed: 38 additions & 9 deletions

File tree

builtin/providers/openstack/config.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/gophercloud/gophercloud"
1111
"github.com/gophercloud/gophercloud/openstack"
12+
"github.com/gophercloud/gophercloud/openstack/objectstorage/v1/swauth"
1213
)
1314

1415
type Config struct {
@@ -21,6 +22,7 @@ type Config struct {
2122
IdentityEndpoint string
2223
Insecure bool
2324
Password string
25+
Swauth bool
2426
TenantID string
2527
TenantName string
2628
Token string
@@ -95,9 +97,12 @@ func (c *Config) loadAndValidate() error {
9597
transport := &http.Transport{Proxy: http.ProxyFromEnvironment, TLSClientConfig: config}
9698
client.HTTPClient.Transport = transport
9799

98-
err = openstack.Authenticate(client, ao)
99-
if err != nil {
100-
return err
100+
// If using Swift Authentication, there's no need to validate authentication normally.
101+
if !c.Swauth {
102+
err = openstack.Authenticate(client, ao)
103+
if err != nil {
104+
return err
105+
}
101106
}
102107

103108
c.osClient = client
@@ -134,6 +139,14 @@ func (c *Config) networkingV2Client(region string) (*gophercloud.ServiceClient,
134139
}
135140

136141
func (c *Config) objectStorageV1Client(region string) (*gophercloud.ServiceClient, error) {
142+
// If Swift Authentication is being used, return a swauth client.
143+
if c.Swauth {
144+
return swauth.NewObjectStorageV1(c.osClient, swauth.AuthOpts{
145+
User: c.Username,
146+
Key: c.Password,
147+
})
148+
}
149+
137150
return openstack.NewObjectStorageV1(c.osClient, gophercloud.EndpointOpts{
138151
Region: region,
139152
Availability: c.getEndpointType(),

builtin/providers/openstack/provider.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ func Provider() terraform.ResourceProvider {
125125
DefaultFunc: schema.EnvDefaultFunc("OS_KEY", ""),
126126
Description: descriptions["key"],
127127
},
128+
129+
"swauth": &schema.Schema{
130+
Type: schema.TypeBool,
131+
Optional: true,
132+
DefaultFunc: schema.EnvDefaultFunc("OS_SWAUTH", ""),
133+
Description: descriptions["swauth"],
134+
},
128135
},
129136

130137
ResourcesMap: map[string]*schema.Resource{
@@ -196,6 +203,9 @@ func init() {
196203
"cert": "A client certificate to authenticate with.",
197204

198205
"key": "A client private key to authenticate with.",
206+
207+
"swauth": "Use Swift's authentication system instead of Keystone. Only used for\n" +
208+
"interaction with Swift.",
199209
}
200210
}
201211

@@ -210,6 +220,7 @@ func configureProvider(d *schema.ResourceData) (interface{}, error) {
210220
IdentityEndpoint: d.Get("auth_url").(string),
211221
Insecure: d.Get("insecure").(bool),
212222
Password: d.Get("password").(string),
223+
Swauth: d.Get("swauth").(bool),
213224
Token: d.Get("token").(string),
214225
TenantID: d.Get("tenant_id").(string),
215226
TenantName: d.Get("tenant_name").(string),

builtin/providers/openstack/resource_openstack_objectstorage_container_v1_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,20 @@ func testAccCheckObjectStorageV1ContainerDestroy(s *terraform.State) error {
5656

5757
var testAccObjectStorageV1Container_basic = fmt.Sprintf(`
5858
resource "openstack_objectstorage_container_v1" "container_1" {
59-
region = "%s"
6059
name = "tf-test-container"
6160
metadata {
6261
test = "true"
6362
}
6463
content_type = "application/json"
65-
}`,
66-
OS_REGION_NAME)
64+
}
65+
`)
6766

6867
var testAccObjectStorageV1Container_update = fmt.Sprintf(`
6968
resource "openstack_objectstorage_container_v1" "container_1" {
70-
region = "%s"
7169
name = "tf-test-container"
7270
metadata {
7371
test = "true"
7472
}
7573
content_type = "text/plain"
76-
}`,
77-
OS_REGION_NAME)
74+
}
75+
`)

website/source/docs/providers/openstack/index.html.markdown

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ The following arguments are supported:
8686
service catalog. It can be set using the OS_ENDPOINT_TYPE environment
8787
variable. If not set, public endpoints is used.
8888

89+
* `swauth` - (Optional) Set to `true` to authenticate against Swauth, a
90+
Swift-native authentication system. If omitted, the `OS_SWAUTH` environment
91+
variable is used. You must also set `username` to the Swauth/Swift username
92+
such as `username:project`. Set the `password` to the Swauth/Swift key.
93+
Finally, set `auth_url` as the location of the Swift service. Note that this
94+
will only work when used with the OpenStack Object Storage resources.
95+
8996
## Rackspace Compatibility
9097

9198
Using this OpenStack provider with Rackspace is not supported and not

0 commit comments

Comments
 (0)