Ready to level-up your engineering skills? Join a Pulumi Workshop. Register Now

Service

A high-level resource for creating a Service in Consul in the Consul catalog. This is appropriate for registering external services and can be used to create services addressable by Consul that cannot be registered with a local agent.

NOTE: If a Consul agent is running on the node where this service is registered, it is not recommended to use this resource as the service will be removed during the next anti-entropy synchronisation.

Example Usage

using Pulumi;
using Consul = Pulumi.Consul;

class MyStack : Stack
{
    public MyStack()
    {
        var compute = new Consul.Node("compute", new Consul.NodeArgs
        {
            Address = "www.google.com",
        });
        var google = new Consul.Service("google", new Consul.ServiceArgs
        {
            Node = compute.Name,
            Port = 80,
            Tags = 
            {
                "tag0",
            },
        });
    }

}
package main

import (
    "github.com/pulumi/pulumi-consul/sdk/v2/go/consul"
    "github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        compute, err := consul.NewNode(ctx, "compute", &consul.NodeArgs{
            Address: pulumi.String("www.google.com"),
        })
        if err != nil {
            return err
        }
        _, err = consul.NewService(ctx, "google", &consul.ServiceArgs{
            Node: compute.Name,
            Port: pulumi.Int(80),
            Tags: pulumi.StringArray{
                pulumi.String("tag0"),
            },
        })
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_consul as consul

compute = consul.Node("compute", address="www.google.com")
google = consul.Service("google",
    node=compute.name,
    port=80,
    tags=["tag0"])
import * as pulumi from "@pulumi/pulumi";
import * as consul from "@pulumi/consul";

const compute = new consul.Node("compute", {
    address: "www.google.com",
});
const google = new consul.Service("google", {
    node: compute.name,
    port: 80,
    tags: ["tag0"],
});

Create a Service Resource

new Service(name: string, args: ServiceArgs, opts?: CustomResourceOptions);
def Service(resource_name: str, opts: Optional[ResourceOptions] = None, address: Optional[str] = None, checks: Optional[Sequence[ServiceCheckArgs]] = None, datacenter: Optional[str] = None, enable_tag_override: Optional[bool] = None, external: Optional[bool] = None, meta: Optional[Mapping[str, str]] = None, name: Optional[str] = None, namespace: Optional[str] = None, node: Optional[str] = None, port: Optional[int] = None, service_id: Optional[str] = None, tags: Optional[Sequence[str]] = None)
func NewService(ctx *Context, name string, args ServiceArgs, opts ...ResourceOption) (*Service, error)
public Service(string name, ServiceArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args ServiceArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
opts ResourceOptions
A bag of options that control this resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args ServiceArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args ServiceArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

Service Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model docs.

Inputs

The Service resource accepts the following input properties:

Node string

The name of the node the to register the service on.

Address string

The address of the service. Defaults to the address of the node.

Checks List<ServiceCheckArgs>
Datacenter string

The datacenter to use. This overrides the agent’s default datacenter and the datacenter in the provider setup.

EnableTagOverride bool

Specifies to disable the anti-entropy feature for this service’s tags. Defaults to false.

External bool

Deprecated: The external field has been deprecated and does nothing.

Meta Dictionary<string, string>

A map of arbitrary KV metadata linked to the service instance.

Name string

The name of the health-check.

Namespace string

The namespace to create the service within.

Port int

The port of the service.

ServiceId string
  • If the service ID is not provided, it will be defaulted to the value of the name attribute.
Tags List<string>

A list of values that are opaque to Consul, but can be used to distinguish between services or nodes.

Node string

The name of the node the to register the service on.

Address string

The address of the service. Defaults to the address of the node.

Checks []ServiceCheck
Datacenter string

The datacenter to use. This overrides the agent’s default datacenter and the datacenter in the provider setup.

EnableTagOverride bool

Specifies to disable the anti-entropy feature for this service’s tags. Defaults to false.

External bool

Deprecated: The external field has been deprecated and does nothing.

Meta map[string]string

A map of arbitrary KV metadata linked to the service instance.

Name string

The name of the health-check.

Namespace string

The namespace to create the service within.

Port int

The port of the service.

ServiceId string
  • If the service ID is not provided, it will be defaulted to the value of the name attribute.
Tags []string

A list of values that are opaque to Consul, but can be used to distinguish between services or nodes.

node string

The name of the node the to register the service on.

address string

The address of the service. Defaults to the address of the node.

checks ServiceCheck[]
datacenter string

The datacenter to use. This overrides the agent’s default datacenter and the datacenter in the provider setup.

enableTagOverride boolean

Specifies to disable the anti-entropy feature for this service’s tags. Defaults to false.

external boolean

Deprecated: The external field has been deprecated and does nothing.

meta {[key: string]: string}

A map of arbitrary KV metadata linked to the service instance.

name string

The name of the health-check.

namespace string

The namespace to create the service within.

port number

The port of the service.

serviceId string
  • If the service ID is not provided, it will be defaulted to the value of the name attribute.
tags string[]

A list of values that are opaque to Consul, but can be used to distinguish between services or nodes.

node str

The name of the node the to register the service on.

address str

The address of the service. Defaults to the address of the node.

checks Sequence[ServiceCheckArgs]
datacenter str

The datacenter to use. This overrides the agent’s default datacenter and the datacenter in the provider setup.

enable_tag_override bool

Specifies to disable the anti-entropy feature for this service’s tags. Defaults to false.

external bool

Deprecated: The external field has been deprecated and does nothing.

meta Mapping[str, str]

A map of arbitrary KV metadata linked to the service instance.

name str

The name of the health-check.

namespace str

The namespace to create the service within.

port int

The port of the service.

service_id str
  • If the service ID is not provided, it will be defaulted to the value of the name attribute.
tags Sequence[str]

A list of values that are opaque to Consul, but can be used to distinguish between services or nodes.

Outputs

All input properties are implicitly available as output properties. Additionally, the Service resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.

Look up an Existing Service Resource

Get an existing Service resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: ServiceState, opts?: CustomResourceOptions): Service
@staticmethod
def get(resource_name: str, id: str, opts: Optional[ResourceOptions] = None, address: Optional[str] = None, checks: Optional[Sequence[ServiceCheckArgs]] = None, datacenter: Optional[str] = None, enable_tag_override: Optional[bool] = None, external: Optional[bool] = None, meta: Optional[Mapping[str, str]] = None, name: Optional[str] = None, namespace: Optional[str] = None, node: Optional[str] = None, port: Optional[int] = None, service_id: Optional[str] = None, tags: Optional[Sequence[str]] = None) -> Service
func GetService(ctx *Context, name string, id IDInput, state *ServiceState, opts ...ResourceOption) (*Service, error)
public static Service Get(string name, Input<string> id, ServiceState? state, CustomResourceOptions? opts = null)
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.

The following state arguments are supported:

Address string

The address of the service. Defaults to the address of the node.

Checks List<ServiceCheckArgs>
Datacenter string

The datacenter to use. This overrides the agent’s default datacenter and the datacenter in the provider setup.

EnableTagOverride bool

Specifies to disable the anti-entropy feature for this service’s tags. Defaults to false.

External bool

Deprecated: The external field has been deprecated and does nothing.

Meta Dictionary<string, string>

A map of arbitrary KV metadata linked to the service instance.

Name string

The name of the health-check.

Namespace string

The namespace to create the service within.

Node string

The name of the node the to register the service on.

Port int

The port of the service.

ServiceId string
  • If the service ID is not provided, it will be defaulted to the value of the name attribute.
Tags List<string>

A list of values that are opaque to Consul, but can be used to distinguish between services or nodes.

Address string

The address of the service. Defaults to the address of the node.

Checks []ServiceCheck
Datacenter string

The datacenter to use. This overrides the agent’s default datacenter and the datacenter in the provider setup.

EnableTagOverride bool

Specifies to disable the anti-entropy feature for this service’s tags. Defaults to false.

External bool

Deprecated: The external field has been deprecated and does nothing.

Meta map[string]string

A map of arbitrary KV metadata linked to the service instance.

Name string

The name of the health-check.

Namespace string

The namespace to create the service within.

Node string

The name of the node the to register the service on.

Port int

The port of the service.

ServiceId string
  • If the service ID is not provided, it will be defaulted to the value of the name attribute.
Tags []string

A list of values that are opaque to Consul, but can be used to distinguish between services or nodes.

address string

The address of the service. Defaults to the address of the node.

checks ServiceCheck[]
datacenter string

The datacenter to use. This overrides the agent’s default datacenter and the datacenter in the provider setup.

enableTagOverride boolean

Specifies to disable the anti-entropy feature for this service’s tags. Defaults to false.

external boolean

Deprecated: The external field has been deprecated and does nothing.

meta {[key: string]: string}

A map of arbitrary KV metadata linked to the service instance.

name string

The name of the health-check.

namespace string

The namespace to create the service within.

node string

The name of the node the to register the service on.

port number

The port of the service.

serviceId string
  • If the service ID is not provided, it will be defaulted to the value of the name attribute.
tags string[]

A list of values that are opaque to Consul, but can be used to distinguish between services or nodes.

address str

The address of the service. Defaults to the address of the node.

checks Sequence[ServiceCheckArgs]
datacenter str

The datacenter to use. This overrides the agent’s default datacenter and the datacenter in the provider setup.

enable_tag_override bool

Specifies to disable the anti-entropy feature for this service’s tags. Defaults to false.

external bool

Deprecated: The external field has been deprecated and does nothing.

meta Mapping[str, str]

A map of arbitrary KV metadata linked to the service instance.

name str

The name of the health-check.

namespace str

The namespace to create the service within.

node str

The name of the node the to register the service on.

port int

The port of the service.

service_id str
  • If the service ID is not provided, it will be defaulted to the value of the name attribute.
tags Sequence[str]

A list of values that are opaque to Consul, but can be used to distinguish between services or nodes.

Supporting Types

ServiceCheck

CheckId string

An ID, unique per agent. Will default to name if not set.

Interval string

The interval to wait between each health-check invocation.

Name string

The name of the health-check.

Timeout string

The timeout value for HTTP checks.

DeregisterCriticalServiceAfter string

The time after which the service is automatically deregistered when in the critical state. Defaults to 30s.

Headers List<ServiceCheckHeaderArgs>

The headers to send for an HTTP check. The attributes of each header is given below.

Http string

The HTTP endpoint to call for an HTTP check.

Method string

The method to use for HTTP health-checks. Defaults to GET.

Notes string

An opaque field meant to hold human readable text.

Status string

The initial health-check status.

Tcp string

The TCP address and port to connect to for a TCP check.

TlsSkipVerify bool

Whether to deactivate certificate verification for HTTP health-checks. Defaults to false.

CheckId string

An ID, unique per agent. Will default to name if not set.

Interval string

The interval to wait between each health-check invocation.

Name string

The name of the health-check.

Timeout string

The timeout value for HTTP checks.

DeregisterCriticalServiceAfter string

The time after which the service is automatically deregistered when in the critical state. Defaults to 30s.

Headers []ServiceCheckHeader

The headers to send for an HTTP check. The attributes of each header is given below.

Http string

The HTTP endpoint to call for an HTTP check.

Method string

The method to use for HTTP health-checks. Defaults to GET.

Notes string

An opaque field meant to hold human readable text.

Status string

The initial health-check status.

Tcp string

The TCP address and port to connect to for a TCP check.

TlsSkipVerify bool

Whether to deactivate certificate verification for HTTP health-checks. Defaults to false.

checkId string

An ID, unique per agent. Will default to name if not set.

interval string

The interval to wait between each health-check invocation.

name string

The name of the health-check.

timeout string

The timeout value for HTTP checks.

deregisterCriticalServiceAfter string

The time after which the service is automatically deregistered when in the critical state. Defaults to 30s.

headers ServiceCheckHeader[]

The headers to send for an HTTP check. The attributes of each header is given below.

http string

The HTTP endpoint to call for an HTTP check.

method string

The method to use for HTTP health-checks. Defaults to GET.

notes string

An opaque field meant to hold human readable text.

status string

The initial health-check status.

tcp string

The TCP address and port to connect to for a TCP check.

tlsSkipVerify boolean

Whether to deactivate certificate verification for HTTP health-checks. Defaults to false.

check_id str

An ID, unique per agent. Will default to name if not set.

interval str

The interval to wait between each health-check invocation.

name str

The name of the health-check.

timeout str

The timeout value for HTTP checks.

deregister_critical_service_after str

The time after which the service is automatically deregistered when in the critical state. Defaults to 30s.

headers Sequence[ServiceCheckHeaderArgs]

The headers to send for an HTTP check. The attributes of each header is given below.

http str

The HTTP endpoint to call for an HTTP check.

method str

The method to use for HTTP health-checks. Defaults to GET.

notes str

An opaque field meant to hold human readable text.

status str

The initial health-check status.

tcp str

The TCP address and port to connect to for a TCP check.

tls_skip_verify bool

Whether to deactivate certificate verification for HTTP health-checks. Defaults to false.

ServiceCheckHeader

Name string

The name of the header.

Values List<string>

The header’s list of values.

Name string

The name of the header.

Values []string

The header’s list of values.

name string

The name of the header.

values string[]

The header’s list of values.

name str

The name of the header.

values Sequence[str]

The header’s list of values.

Package Details

Repository
https://github.com/pulumi/pulumi-consul
License
Apache-2.0
Notes
This Pulumi package is based on the consul Terraform Provider.