provider/Consul: Support Token. Fixes #378

This commit is contained in:
Armon Dadgar 2014-10-13 11:42:40 -07:00
parent 3e249a4e4e
commit 269c5be738
2 changed files with 25 additions and 4 deletions

View File

@ -26,6 +26,11 @@ func resourceConsulKeys() *schema.Resource {
ForceNew: true,
},
"token": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"keys": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
@ -95,10 +100,14 @@ func resourceConsulKeysCreate(d *schema.ResourceData, meta interface{}) error {
return err
}
}
var token string
if v := d.Get("token"); v != nil {
token = v.(string)
}
// Setup the operations using the datacenter
qOpts := consulapi.QueryOptions{Datacenter: dc}
wOpts := consulapi.WriteOptions{Datacenter: dc}
qOpts := consulapi.QueryOptions{Datacenter: dc, Token: token}
wOpts := consulapi.WriteOptions{Datacenter: dc, Token: token}
// Store the computed vars
vars := make(map[string]string)
@ -157,9 +166,13 @@ func resourceConsulKeysRead(d *schema.ResourceData, meta interface{}) error {
} else {
return fmt.Errorf("Missing datacenter configuration")
}
var token string
if v := d.Get("token"); v != nil {
token = v.(string)
}
// Setup the operations using the datacenter
qOpts := consulapi.QueryOptions{Datacenter: dc}
qOpts := consulapi.QueryOptions{Datacenter: dc, Token: token}
// Store the computed vars
vars := make(map[string]string)
@ -201,9 +214,13 @@ func resourceConsulKeysDelete(d *schema.ResourceData, meta interface{}) error {
} else {
return fmt.Errorf("Missing datacenter configuration")
}
var token string
if v := d.Get("token"); v != nil {
token = v.(string)
}
// Setup the operations using the datacenter
wOpts := consulapi.WriteOptions{Datacenter: dc}
wOpts := consulapi.WriteOptions{Datacenter: dc, Token: token}
// Extract the keys
keys := d.Get("keys").(*schema.Set).List()

View File

@ -16,6 +16,7 @@ and to expose infrastructure details to clients.
```
resource "consul_keys" "app" {
datacenter = "nyc1"
token = "abcd"
# Read the launch AMI from Consul
key {
@ -46,6 +47,9 @@ The following arguments are supported:
* `datacenter` - (Optional) The datacenter to use. This overrides the
datacenter in the provider setup and the agent's default datacenter.
* `token` - (Optional) The ACL token to use. This overrides the
token that the agent provides by default.
* `key` - (Required) Specifies a key in Consul to be read or written.
Supported values documented below.