2014-07-27 02:42:25 +02:00
|
|
|
---
|
|
|
|
layout: "consul"
|
|
|
|
page_title: "Consul: consul_keys"
|
|
|
|
sidebar_current: "docs-consul-resource-keys"
|
|
|
|
---
|
|
|
|
|
|
|
|
# consul\_keys
|
|
|
|
|
|
|
|
Provides access to Key/Value data in Consul. This can be used
|
|
|
|
to both read keys from Consul, but also to set the value of keys
|
|
|
|
in Consul. This is a powerful way dynamically set values in templates,
|
|
|
|
and to expose infrastructure details to clients.
|
|
|
|
|
|
|
|
## Example Usage
|
|
|
|
|
|
|
|
```
|
|
|
|
resource "consul_keys" "app" {
|
|
|
|
datacenter = "nyc1"
|
|
|
|
|
|
|
|
# Read the launch AMI from Consul
|
|
|
|
key {
|
|
|
|
name = "ami"
|
|
|
|
path = "service/app/launch_ami"
|
|
|
|
default = "ami-1234"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Set the CNAME of our load balancer as a key
|
|
|
|
key {
|
|
|
|
name = "elb_cname"
|
|
|
|
path = "service/app/elb_address"
|
|
|
|
value = "${aws_elb.app.dns_name}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Start our instance with the dynamic ami value
|
|
|
|
resource "aws_instance" "app" {
|
|
|
|
ami = "${consul_keys.app.var.ami}"
|
|
|
|
...
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Argument Reference
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
* `key` - (Required) Specifies a key in Consul to be read or written.
|
|
|
|
Supported values documented below.
|
|
|
|
|
|
|
|
The `key` block supports the following:
|
|
|
|
|
|
|
|
* `name` - (Required) This is the name of the key. This value of the
|
|
|
|
key is exposed as `var.<name>`. This is not the path of the key
|
|
|
|
in Consul.
|
|
|
|
|
|
|
|
* `path` - (Required) This is the path in Consul that should be read
|
|
|
|
or written to.
|
|
|
|
|
|
|
|
* `default` - (Optional) This is the default value to set for `var.<name>`
|
|
|
|
if the key does not exist in Consul. Defaults to the empty string.
|
|
|
|
|
|
|
|
* `value` - (Optional) If set, the key will be set to this value.
|
|
|
|
This allows a key to be written to.
|
|
|
|
|
|
|
|
* `delete` - (Optional) If true, then the key will be deleted when
|
2014-07-29 07:50:20 +02:00
|
|
|
the resource is destroyed. Otherwise, it will be left in Consul.
|
2014-07-27 02:42:25 +02:00
|
|
|
Defaults to false.
|
|
|
|
|
|
|
|
## Attributes Reference
|
|
|
|
|
|
|
|
The following attributes are exported:
|
|
|
|
|
|
|
|
* `datacenter` - The datacenter the keys are being read/written to.
|
|
|
|
* `var.<name>` - For each name given, the corresponding attribute
|
|
|
|
has the value of the key.
|
|
|
|
|