1. Packages
  2. Consul Provider
Consul v3.12.1 published on Friday, Aug 23, 2024 by Pulumi

Consul Provider

consul logo
Consul v3.12.1 published on Friday, Aug 23, 2024 by Pulumi

    Installation

    The consul provider is available as a package in all Pulumi languages:

    Consul is a service networking platform which provides service discovery, service mesh, and application configuration capabilities. The Consul provider exposes resources used to interact with a Consul cluster. Configuration of the provider is optional, as it provides reasonable defaults for all arguments.

    Use the navigation to the left to read about the available resources.

    Example Usage

    # Pulumi.yaml provider configuration file
    name: configuration-example
    runtime: nodejs
    config:
        consul:address:
            value: demo.consul.io:80
        consul:datacenter:
            value: nyc1
    
    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    import * as consul from "@pulumi/consul";
    
    // Access a key in Consul
    const app = consul.getKeys({
        keys: [{
            name: "ami",
            path: "service/app/launch_ami",
            "default": "ami-1234",
        }],
    });
    // Use our variable from Consul
    const appInstance = new aws.ec2.Instance("app", {ami: app.then(app => app["var"]?.ami)});
    
    # Pulumi.yaml provider configuration file
    name: configuration-example
    runtime: python
    config:
        consul:address:
            value: demo.consul.io:80
        consul:datacenter:
            value: nyc1
    
    import pulumi
    import pulumi_aws as aws
    import pulumi_consul as consul
    
    # Access a key in Consul
    app = consul.get_keys(keys=[{
        "name": "ami",
        "path": "service/app/launch_ami",
        "default": "ami-1234",
    }])
    # Use our variable from Consul
    app_instance = aws.ec2.Instance("app", ami=app.var["ami"])
    
    # Pulumi.yaml provider configuration file
    name: configuration-example
    runtime: dotnet
    config:
        consul:address:
            value: demo.consul.io:80
        consul:datacenter:
            value: nyc1
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    using Consul = Pulumi.Consul;
    
    return await Deployment.RunAsync(() =>
    {
        // Access a key in Consul
        var app = Consul.GetKeys.Invoke(new()
        {
            Keys = new[]
            {
                new Consul.Inputs.GetKeysKeyInputArgs
                {
                    Name = "ami",
                    Path = "service/app/launch_ami",
                    Default = "ami-1234",
                },
            },
        });
    
        // Use our variable from Consul
        var appInstance = new Aws.Ec2.Instance("app", new()
        {
            Ami = app.Apply(getKeysResult => getKeysResult.Var?.Ami),
        });
    
    });
    
    # Pulumi.yaml provider configuration file
    name: configuration-example
    runtime: go
    config:
        consul:address:
            value: demo.consul.io:80
        consul:datacenter:
            value: nyc1
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
    	"github.com/pulumi/pulumi-consul/sdk/v3/go/consul"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		// Access a key in Consul
    		app, err := consul.LookupKeys(ctx, &consul.LookupKeysArgs{
    			Keys: []consul.GetKeysKey{
    				{
    					Name:    "ami",
    					Path:    "service/app/launch_ami",
    					Default: pulumi.StringRef("ami-1234"),
    				},
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		// Use our variable from Consul
    		_, err = ec2.NewInstance(ctx, "app", &ec2.InstanceArgs{
    			Ami: pulumi.String(app.Var.Ami),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    # Pulumi.yaml provider configuration file
    name: configuration-example
    runtime: yaml
    config:
        consul:address:
            value: demo.consul.io:80
        consul:datacenter:
            value: nyc1
    
    resources:
      # Use our variable from Consul
      appInstance:
        type: aws:ec2:Instance
        name: app
        properties:
          ami: ${app.var.ami}
    variables:
      # Access a key in Consul
      app:
        fn::invoke:
          Function: consul:getKeys
          Arguments:
            keys:
              - name: ami
                path: service/app/launch_ami
                default: ami-1234
    
    # Pulumi.yaml provider configuration file
    name: configuration-example
    runtime: java
    config:
        consul:address:
            value: demo.consul.io:80
        consul:datacenter:
            value: nyc1
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.consul.ConsulFunctions;
    import com.pulumi.consul.inputs.GetKeysArgs;
    import com.pulumi.aws.ec2.Instance;
    import com.pulumi.aws.ec2.InstanceArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            // Access a key in Consul
            final var app = ConsulFunctions.getKeys(GetKeysArgs.builder()
                .keys(GetKeysKeyArgs.builder()
                    .name("ami")
                    .path("service/app/launch_ami")
                    .default_("ami-1234")
                    .build())
                .build());
    
            // Use our variable from Consul
            var appInstance = new Instance("appInstance", InstanceArgs.builder()
                .ami(app.applyValue(getKeysResult -> getKeysResult.var().ami()))
                .build());
    
        }
    }
    

    Schema

    Optional

    • address (String) The HTTP(S) API address of the agent to use. Defaults to “127.0.0.1:8500”.
    • authJwt (Block List, Max: 1) Authenticates to Consul using a JWT authentication method. (see below for nested schema)
    • caFile (String) A path to a PEM-encoded certificate authority used to verify the remote agent’s certificate.
    • caPath (String) A path to a directory of PEM-encoded certificate authority files to use to check the authenticity of client and server connections. Can also be specified with the CONSUL_CAPATH environment variable.
    • caPem (String) PEM-encoded certificate authority used to verify the remote agent’s certificate.
    • certFile (String) A path to a PEM-encoded certificate provided to the remote agent; requires use of keyFile or keyPem.
    • certPem (String) PEM-encoded certificate provided to the remote agent; requires use of keyFile or keyPem.
    • datacenter (String) The datacenter to use. Defaults to that of the agent.
    • header (Block List) A configuration block, described below, that provides additional headers to be sent along with all requests to the Consul server. This block can be specified multiple times. (see below for nested schema)
    • httpAuth (String) HTTP Basic Authentication credentials to be used when communicating with Consul, in the format of either user or user:pass. This may also be specified using the CONSUL_HTTP_AUTH environment variable.
    • insecureHttps (Boolean) Boolean value to disable SSL certificate verification; setting this value to true is not recommended for production use. Only use this with scheme set to “https”.
    • keyFile (String) A path to a PEM-encoded private key, required if certFile or certPem is specified.
    • keyPem (String) PEM-encoded private key, required if certFile or certPem is specified.
    • namespace (String)
    • scheme (String) The URL scheme of the agent to use (“http” or “https”). Defaults to “http”.
    • token (String, Sensitive) The ACL token to use by default when making requests to the agent. Can also be specified with CONSUL_HTTP_TOKEN or CONSUL_TOKEN as an environment variable.

    Nested Schema for authJwt

    Required:

    • authMethod (String) The name of the auth method to use for login.

    Optional:

    • bearerToken (String) The bearer token to present to the auth method during login for authentication purposes. For the Kubernetes auth method this is a Service Account Token (JWT).
    • meta (Map of String) Specifies arbitrary KV metadata linked to the token. Can be useful to track origins.
    • usePulumiCloudWorkloadIdentity (Boolean) Whether to use a Pulumi Workload Identity token. The token will be read from the TFC_WORKLOAD_IDENTITY_TOKEN environment variable.

    Nested Schema for header

    Required:

    • name (String) The name of the header.
    • value (String) The value of the header.

    Environment Variables

    All environment variables listed in the Consul environment variables documentation are supported by the Pulumi provider.

    consul logo
    Consul v3.12.1 published on Friday, Aug 23, 2024 by Pulumi