Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/consul: consul_key_prefix resource #5988

Merged
merged 1 commit into from
Apr 5, 2016
Merged

provider/consul: consul_key_prefix resource #5988

merged 1 commit into from
Apr 5, 2016

Conversation

apparentlymart
Copy link
Contributor

This new resource is an alternative to consul_keys that manages all keys under a given prefix, rather than arbitrary single keys across the entire store. This is based on my proposal in #5211, but differs from that earlier proposal due to some further design iteration.

  • Implementation
  • Tests
  • Documentation

The primary change to the design is to refer to the idea of a "prefix" rather than a "subtree", since that is more consistent with Consul's data model and terminology used within its API.

Here is an example of how it might be used:

resource "consul_key_prefix" "baz" {
    path_prefix = "test/sandwich/"

    subkeys = {
        // Individual sub-keys
        "cheese_type" = "chevre"
        "meat_type" = "ham"
        "bread_type" = "baguette"

        // Consul has a convention where sets can be managed as a "folder" of values.
        // We can create such a set, and this resource will automatically add/remove members
        // as required.
        "veggies/tomato" = "tomato"
        "veggies/lettuce" = "lettuce"
    }
}

This will create the following full keys in Consul:

  • test/sandwich/cheese_type
  • test/sandwich/meat_type
  • test/sandwich/bread_type
  • test/sandwich/veggies/tomato
  • test/sandwich/veggies/lettuce

Here's an example of a diff created when changing to a different kind of cheese, leaving everything else unchanged:

~ consul_key_prefix.baz
    subkeys.cheese_type: "chevre" => "brie"

The key advantage of this resource over consul_keys is that it is able to detect and delete keys that are added outside of Terraform, whereas consul_keys is only able to detect changes to keys it is explicitly managing. It will also delete the entire subtree under the given prefix when the resource is deleted, since in this case Terraform is considered to be exclusively managing that entire keyspace.

Along with that initial motivation, this resource also serves to serve the need that motivated my earlier proposal #3164: rather than using Terraform's remote state mechanism as a means to pass around bundles of key/value pairs, this resource provides a robust means to manage such bundles directly within Consul, at least so long as Consul was the backend being used with terraform_synthetic_state (which it is in my case). One could imagine a similar resource aws_s3_bucket_object_prefix that manages a collection of related S3 bucket objects in the same way, since S3's data model is similar to Consul's.

@apparentlymart apparentlymart self-assigned this Apr 2, 2016
@apparentlymart apparentlymart changed the title provider/consul: consul_key_prefix resource [WIP] provider/consul: consul_key_prefix resource Apr 2, 2016
This new resource is an alternative to consul_keys that manages all keys
under a given prefix, rather than arbitrary single keys across the entire
store.

The key advantage of this resource over consul_keys is that it is able to
detect and delete keys that are added outside of Terraform, whereas
consul_keys is only able to detect changes to keys it is explicitly
managing.
@apparentlymart apparentlymart changed the title [WIP] provider/consul: consul_key_prefix resource provider/consul: consul_key_prefix resource Apr 3, 2016
@jen20
Copy link
Contributor

jen20 commented Apr 5, 2016

This LGTM! Thanks @apparentlymart!

@jen20 jen20 merged commit fe4ddba into hashicorp:master Apr 5, 2016
apparentlymart added a commit that referenced this pull request Apr 22, 2016
This file was missed when committing the doc changes for #5988.
catsby pushed a commit that referenced this pull request Apr 22, 2016
This file was missed when committing the doc changes for #5988.
@ghost
Copy link

ghost commented Apr 26, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants