The consul_keys
datasource reads values from the Consul key/value store. This is a powerful way to dynamically set values in templates.
data "consul_keys" "app" {
datacenter = "nyc1"
# Read the launch AMI from Consul
key {
name = "ami"
path = "service/app/launch_ami"
default = "ami-1234"
}
}
# Start our instance with the dynamic ami value
resource "aws_instance" "app" {
ami = data.consul_keys.app.var.ami
# ...
}
datacenter
(String) The datacenter to use. This overrides the agent's default datacenter and the datacenter in the provider setup.error_on_missing_keys
(Boolean) Whether to return an error when a key is absent from the KV store and no default is configured. This defaults to false
.key
(Block Set) Specifies a key in Consul to be read. Supported values documented below. Multiple blocks supported. (see below for nested schema)namespace
(String) The namespace to lookup the keys.partition
(String) The partition to lookup the keys.token
(String, Sensitive, Deprecated) The ACL token to use. This overrides the token that the agent provides by default.id
(String) The ID of this resource.var
(Map of String) For each name given, the corresponding attribute has the value of the key.key
Required:
name
(String) 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
(String) This is the path in Consul that should be read or written to.Optional:
default
(String) This is the default value to set for var.<name>
if the key does not exist in Consul. Defaults to an empty string.