» consul_service
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.
» Example Usage
data "consul_service" "read-consul-dc1" {
name = "consul"
# Optional parameter: implicitly uses the current datacenter of the agent
datacenter = "dc1"
}
# Set the description to a whitespace delimited list of the node names
resource "example_resource" "app" {
description = "${join(" ", data.consul_service.nodes)}"
# ...
}
» Argument Reference
The following arguments are supported:
-
datacenter
- (Optional) The Consul datacenter to query. Defaults to the same value found inquery_options
parameter specified below, or if that is empty, thedatacenter
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) Whentrue
, the default, allow responses from Consul servers that are followers. -
require_consistent
- (Optional) Whentrue
force the client to perform a read on at least quorum servers and verify the result is the same. Defaults tofalse
. -
token
- (Optional) Specify the Consul ACL token to use when performing the request. This defaults to the same API token configured by theconsul
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.
» Attributes Reference
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 inservice
. -
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 theServiceAddress
in the Consul catalog is empty, this value is automatically populated with thenode_address
(theAddress
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.