github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/website/source/docs/providers/consul/r/prepared_query.markdown (about) 1 --- 2 layout: "consul" 3 page_title: "Consul: consul_prepared_query" 4 sidebar_current: "docs-consul-resource-prepared-query" 5 description: |- 6 Allows Terraform to manage a Consul prepared query 7 --- 8 9 # consul\_prepared\_query 10 11 Allows Terraform to manage a Consul prepared query. 12 13 Managing prepared queries is done using Consul's REST API. This resource is 14 useful to provide a consistent and declarative way of managing prepared 15 queries in your Consul cluster using Terraform. 16 17 ## Example Usage 18 19 ``` 20 resource "consul_prepared_query" "service-near-self" { 21 datacenter = "nyc1" 22 token = "abcd" 23 stored_token = "wxyz" 24 name = "" 25 only_passing = true 26 near = "_agent" 27 28 template { 29 type = "name_prefix_match" 30 regexp = "^(.*)-near-self$" 31 } 32 33 service = "$${match(1)}" 34 35 failover { 36 nearest_n = 3 37 datacenters = ["dc2", "dc3", "dc4"] 38 } 39 40 dns { 41 ttl = "5m" 42 } 43 44 } 45 ``` 46 47 ## Argument Reference 48 49 The following arguments are supported: 50 51 * `datacenter` - (Optional) The datacenter to use. This overrides the 52 datacenter in the provider setup and the agent's default datacenter. 53 54 * `token` - (Optional) The ACL token to use when saving the prepared query. 55 This overrides the token that the agent provides by default. 56 57 * `stored_token` - (Optional) The ACL token to store with the prepared 58 query. This token will be used by default whenever the query is executed. 59 60 * `name` - (Required) The name of the prepared query. Used to identify 61 the prepared query during requests. Can be specified as an empty string 62 to configure the query as a catch-all. 63 64 * `service` - (Required) The name of the service to query. 65 66 * `only_passing` - (Optional) When true, the prepared query will only 67 return nodes with passing health checks in the result. 68 69 * `near` - (Optional) Allows specifying the name of a node to sort results 70 near using Consul's distance sorting and network coordinates. The magic 71 `_agent` value can be used to always sort nearest the node servicing the 72 request. 73 74 * `failover` - (Optional) Options for controlling behavior when no healthy 75 nodes are available in the local DC. 76 77 * `nearest_n` - (Optional) Return results from this many datacenters, 78 sorted in ascending order of estimated RTT. 79 80 * `datacenters` - (Optional) Remote datacenters to return results from. 81 82 * `dns` - (Optional) Settings for controlling the DNS response details. 83 84 * `ttl` - (Optional) The TTL to send when returning DNS results. 85 86 * `template` - (Optional) Query templating options. This is used to make a 87 single prepared query respond to many different requests. 88 89 * `type` - (Required) The type of template matching to perform. Currently 90 only `name_prefix_match` is supported. 91 92 * `regexp` - (Required) The regular expression to match with. When using 93 `name_prefix_match`, this regex is applied against the query name. 94 95 ## Attributes Reference 96 97 The following attributes are exported: 98 99 * `id` - The ID of the prepared query, generated by Consul.