Make 'endpoints' a schema.TypeList.
This commit is contained in:
parent
fee5cabeda
commit
70aad79b6e
|
@ -6,16 +6,19 @@ import (
|
|||
etcdv3 "github.com/coreos/etcd/clientv3"
|
||||
"github.com/hashicorp/terraform/backend"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func New() backend.Backend {
|
||||
s := &schema.Backend{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"endpoints": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
},
|
||||
MinItems: 1,
|
||||
Required: true,
|
||||
Description: "Comma-separated list of endpoints for the etcd cluster.",
|
||||
Description: "Endpoints for the etcd cluster.",
|
||||
},
|
||||
|
||||
"username": &schema.Schema{
|
||||
|
@ -77,8 +80,8 @@ func (b *Backend) configure(ctx context.Context) error {
|
|||
func (b *Backend) rawClient() (*etcdv3.Client, error) {
|
||||
config := etcdv3.Config{}
|
||||
|
||||
if v, ok := b.data.GetOk("endpoints"); ok && v.(string) != "" {
|
||||
config.Endpoints = strings.Split(v.(string), ",")
|
||||
if v, ok := b.data.GetOk("endpoints"); ok {
|
||||
config.Endpoints = retrieveEndpoints(v)
|
||||
}
|
||||
if v, ok := b.data.GetOk("username"); ok && v.(string) != "" {
|
||||
config.Username = v.(string)
|
||||
|
@ -89,3 +92,12 @@ func (b *Backend) rawClient() (*etcdv3.Client, error) {
|
|||
|
||||
return etcdv3.New(config)
|
||||
}
|
||||
|
||||
func retrieveEndpoints(v interface{}) []string {
|
||||
var endpoints []string
|
||||
list := v.([]interface{})
|
||||
for _, ep := range list {
|
||||
endpoints = append(endpoints, ep.(string))
|
||||
}
|
||||
return endpoints
|
||||
}
|
||||
|
|
|
@ -12,6 +12,10 @@ import (
|
|||
"github.com/hashicorp/terraform/backend"
|
||||
)
|
||||
|
||||
var (
|
||||
etcdv3Endpoints = strings.Split(os.Getenv("TF_ETCDV3_ENDPOINTS"), ",")
|
||||
)
|
||||
|
||||
const (
|
||||
keyPrefix = "tf-unit"
|
||||
)
|
||||
|
@ -28,7 +32,7 @@ func prepareEtcdv3(t *testing.T) {
|
|||
}
|
||||
|
||||
client, err := etcdv3.New(etcdv3.Config{
|
||||
Endpoints: strings.Split(os.Getenv("TF_ETCDV3_ENDPOINTS"), ","),
|
||||
Endpoints: etcdv3Endpoints,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -49,12 +53,12 @@ func TestBackend(t *testing.T) {
|
|||
|
||||
// Get the backend. We need two to test locking.
|
||||
b1 := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
||||
"endpoints": os.Getenv("TF_ETCDV3_ENDPOINTS"),
|
||||
"endpoints": etcdv3Endpoints,
|
||||
"prefix": path,
|
||||
})
|
||||
|
||||
b2 := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
||||
"endpoints": os.Getenv("TF_ETCDV3_ENDPOINTS"),
|
||||
"endpoints": etcdv3Endpoints,
|
||||
"prefix": path,
|
||||
})
|
||||
|
||||
|
@ -69,13 +73,13 @@ func TestBackend_lockDisabled(t *testing.T) {
|
|||
|
||||
// Get the backend. We need two to test locking.
|
||||
b1 := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
||||
"endpoints": os.Getenv("TF_ETCDV3_ENDPOINTS"),
|
||||
"endpoints": etcdv3Endpoints,
|
||||
"lock": false,
|
||||
"prefix": key,
|
||||
})
|
||||
|
||||
b2 := backend.TestBackendConfig(t, New(), map[string]interface{}{
|
||||
"endpoints": os.Getenv("TF_ETCDV3_ENDPOINTS"),
|
||||
"endpoints": etcdv3Endpoints,
|
||||
"lock": false,
|
||||
"prefix": key + "/" + "different", // Diff so locking test would fail if it was locking
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue