add options for openstack identity v3
This commit is contained in:
parent
b0e8cd5dd3
commit
bfe492d407
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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.",
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue