provider/consul: consul_key_prefix resource #5988
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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:
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:
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, whereasconsul_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 resourceaws_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.