/
config.go
47 lines (38 loc) · 1.05 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"github.com/hanazuki/terraform-provider-conoha/conoha"
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack"
)
type Config struct {
Username string
Password string
TenantName string
Region string
}
func (c *Config) client() (*gophercloud.ProviderClient, error) {
options := gophercloud.AuthOptions{
IdentityEndpoint: fmt.Sprintf("https://identity.%s.conoha.io/v2.0", c.Region),
Username: c.Username,
Password: c.Password,
TenantName: c.TenantName,
}
return openstack.AuthenticatedClient(options)
}
func (c *Config) computeClient() (*gophercloud.ServiceClient, error) {
providerClient, err := c.client()
if err != nil {
return nil, err
}
return openstack.NewComputeV2(providerClient,
gophercloud.EndpointOpts{Region: c.Region})
}
func (c *Config) dnsClient() (*gophercloud.ServiceClient, error) {
providerClient, err := c.client()
if err != nil {
return nil, err
}
return conoha.NewDnsV1(providerClient,
gophercloud.EndpointOpts{Region: c.Region})
}