The consul_config_entry_service_splitter
resource configures a service splitter that will redirect a percentage of incoming traffic requests for a service to one or more specific service instances.
resource "consul_config_entry" "web" {
name = "web"
kind = "service-defaults"
config_json = jsonencode({
Protocol = "http"
Expose = {}
MeshGateway = {}
TransparentProxy = {}
})
}
resource "consul_config_entry_service_resolver" "service_resolver" {
name = "service-resolver"
default_subset = "v1"
subsets {
name = "v1"
filter = "Service.Meta.version == v1"
}
subsets {
name = "v2"
Filter = "Service.Meta.version == v2"
}
}
resource "consul_config_entry_service_splitter" "foo" {
name = consul_config_entry_service_resolver.service_resolver.name
meta = {
key = "value"
}
splits {
weight = 80
service = "web"
service_subset = "v1"
request_headers {
set = {
"x-web-version" = "from-v1"
}
}
response_headers {
set = {
"x-web-version" = "to-v1"
}
}
}
splits {
weight = 10
service = "web"
service_subset = "v2"
request_headers {
set = {
"x-web-version" = "from-v2"
}
}
response_headers {
set = {
"x-web-version" = "to-v2"
}
}
}
splits {
weight = 10
service = "web"
service_subset = "v2"
}
}
name
(String) Specifies a name for the configuration entry.splits
(Block List, Min: 1) Defines how much traffic to send to sets of service instances during a traffic split. (see below for nested schema)meta
(Map of String) Specifies key-value pairs to add to the KV store.namespace
(String) Specifies the namespace to apply the configuration entry.partition
(String) Specifies the admin partition to apply the configuration entry.id
(String) The ID of this resource.splits
Required:
service
(String) Specifies the name of the service to resolve.weight
(Number) Specifies the percentage of traffic sent to the set of service instances specified in the service
field. Each weight must be a floating integer between 0
and 100
. The smallest representable value is .01
. The sum of weights across all splits must add up to 100
.Optional:
namespace
(String) Specifies the namespace to use in the FQDN when resolving the service.partition
(String) Specifies the admin partition to use in the FQDN when resolving the service.request_headers
(Block List, Max: 1) Specifies a set of HTTP-specific header modification rules applied to requests routed with the service split. You cannot configure request headers if the listener protocol is set to tcp
. (see below for nested schema)response_headers
(Block List, Max: 1) Specifies a set of HTTP-specific header modification rules applied to responses routed with the service split. You cannot configure request headers if the listener protocol is set to tcp
. (see below for nested schema)service_subset
(String) Specifies a subset of the service to resolve. A service subset assigns a name to a specific subset of discoverable service instances within a datacenter, such as version2
or canary
. All services have an unnamed default subset that returns all healthy instances.splits.request_headers
Optional:
add
(Map of String) Map of one or more key-value pairs. Defines a set of key-value pairs to add to the header. Use header names as the keys. Header names are not case-sensitive. If header values with the same name already exist, the value is appended and Consul applies both headers.remove
(List of String) Defines an list of headers to remove. Consul removes only headers containing exact matches. Header names are not case-sensitive.set
(Map of String) Map of one or more key-value pairs. Defines a set of key-value pairs to add to the request header or to replace existing header values with. Use header names as the keys. Header names are not case-sensitive. If header values with the same names already exist, Consul replaces the header values.splits.response_headers
Optional:
add
(Map of String) Map of one or more key-value pairs. Defines a set of key-value pairs to add to the header. Use header names as the keys. Header names are not case-sensitive. If header values with the same name already exist, the value is appended and Consul applies both headers.remove
(List of String) Defines an list of headers to remove. Consul removes only headers containing exact matches. Header names are not case-sensitive.set
(Map of String) Map of one or more key-value pairs. Defines a set of key-value pairs to add to the request header or to replace existing header values with. Use header names as the keys. Header names are not case-sensitive. If header values with the same names already exist, Consul replaces the header values.Import is supported using the following syntax:
terraform import consul_config_entry_service_splitter.foo web