consul_service provides details about a specific Consul service in a given datacenter. The results include a list of nodes advertising the specified service, the node's IP address, port number, node ID, etc. By specifying a different datacenter in the query_options it is possible to retrieve a list of services from a different WAN-attached Consul datacenter.
This data source is different from the consul_services (plural) data source, which provides a summary of the current Consul services.
data "consul_service" "read-consul-dc1" {
query_options {
# Optional parameter: implicitly uses the current datacenter of the agent
datacenter = "dc1"
}
name = "consul"
}
# Set the description to a whitespace delimited list of the node names
resource "example_resource" "app" {
description = "${join(" ", data.consul_service.nodes)}"
# ...
}
The following arguments are supported:
datacenter - (Optional) The Consul datacenter to query. Defaults to the same value found in query_options parameter specified below, or if that is empty, the datacenter value found in the Consul agent that this provider is configured to talk to.
name - (Required) The service name to select.
query_options - (Optional) See below.
tag - (Optional) A single tag that can be used to filter the list of nodes to return based on a single matching tag..
The query_options block supports the following:
allow_stale - (Optional) When true, the default, allow responses from Consul servers that are followers.
require_consistent - (Optional) When true force the client to perform a read on at least quorum servers and verify the result is the same. Defaults to false.
token - (Optional) Specify the Consul ACL token to use when performing the request. This defaults to the same API token configured by the consul provider but may be overriden if necessary.
wait_index - (Optional) Index number used to enable blocking quereis.
wait_time - (Optional) Max time the client should wait for a blocking query to return.
The following attributes are exported:
datacenter - The datacenter the keys are being read from to. name - The name of the service tag - The name of the tag used to filter the list of nodes in service. service - A list of nodes and details about each endpoint advertising a service. Each element in the list is a map of attributes that correspond to each individual node. The list of per-node attributes is detailed below. The following is a list of the per-node service attributes:
create_index - The index entry at which point this entry was added to the catalog. modify_index - The index entry at which point this entry was modified in the catalog. node_address - The address of the Consul node advertising the service. node_id - The Node ID of the Consul agent advertising the service. node_meta - Node meta data tag information, if any. node_name - The name of the Consul node. address - The IP address of the service. If the ServiceAddress in the Consul catalog is empty, this value is automatically populated with the node_address (the Address in the Consul Catalog). enable_tag_override - Whether service tags can be overridden on this service. id - A unique service instance identifier. name - The name of the service. port - Port number of the service. tagged_addresses - List of explicit LAN and WAN IP addresses for the agent. tags - List of tags for the service.
© 2018 HashiCorpLicensed under the MPL 2.0 License.
https://www.terraform.io/docs/providers/consul/d/service.html