consul_key_prefix

Allows Terraform to manage a "namespace" of Consul keys that share a common name prefix.

Like consul_keys, this resource can write values into the Consul key/value store, but unlike consul_keys this resource can detect and remove extra keys that have been added some other way, thus ensuring that rogue data added outside of Terraform will be removed on the next run.

This resource is thus useful in the case where Terraform is exclusively managing a set of related keys.

To avoid accidentally clobbering matching data that existed in Consul before a consul_key_prefix resource was created, creation of a key prefix instance will fail if any matching keys are already present in the key/value store. If any conflicting data is present, you must first delete it manually or explicitly import the prefix.

Example Usage

resource "consul_key_prefix" "myapp_config" {
  datacenter = "nyc1"
  token      = "abcd"

  # Prefix to add to prepend to all of the subkey names below.
  path_prefix = "myapp/config/"

  subkeys = {
    "elb_cname"         = "${aws_elb.app.dns_name}"
    "s3_bucket_name"    = "${aws_s3_bucket.app.bucket}"
    "database/hostname" = "${aws_db_instance.app.address}"
    "database/port"     = "${aws_db_instance.app.port}"
    "database/username" = "${aws_db_instance.app.username}"
    "database/name"     = "${aws_db_instance.app.name}"
  }

  subkey {
    path  = "database/password"
    value = "${aws_db_instance.app.password}"
    flags = 2
  }

}

Argument Reference

The following arguments are supported:

The subkey block supports the following:

Attributes Reference

The following attributes are exported:

Import

consul_key_prefix can be imported. This is useful when the path already exists and you know all keys in path should be managed by Terraform.

$ terraform import consul_key_prefix.myapp_config myapp/config/