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

getKeys

The consul.Keys resource reads values from the Consul key/value store. This is a powerful way dynamically set values in templates.

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;
using Consul = Pulumi.Consul;

class MyStack : Stack
{
    public MyStack()
    {
        var appKeys = Output.Create(Consul.GetKeys.InvokeAsync(new Consul.GetKeysArgs
        {
            Datacenter = "nyc1",
            Keys = 
            {
                new Consul.Inputs.GetKeysKeyArgs
                {
                    Default = "ami-1234",
                    Name = "ami",
                    Path = "service/app/launch_ami",
                },
            },
            Token = "abcd",
        }));
        // Start our instance with the dynamic ami value
        var appInstance = new Aws.Ec2.Instance("appInstance", new Aws.Ec2.InstanceArgs
        {
            Ami = appKeys.Apply(appKeys => appKeys.Var.Ami),
        });
    }

}
package main

import (
    "github.com/pulumi/pulumi-aws/sdk/v3/go/aws/ec2"
    "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 {
        opt0 := "nyc1"
        opt1 := "abcd"
        appKeys, err := consul.LookupKeys(ctx, &consul.LookupKeysArgs{
            Datacenter: &opt0,
            Keys: []consul.GetKeysKey{
                consul.GetKeysKey{
                    Default: "ami-1234",
                    Name:    "ami",
                    Path:    "service/app/launch_ami",
                },
            },
            Token: &opt1,
        }, nil)
        if err != nil {
            return err
        }
        _, err = ec2.NewInstance(ctx, "appInstance", &ec2.InstanceArgs{
            Ami: pulumi.String(appKeys.Var.Ami),
        })
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_aws as aws
import pulumi_consul as consul

app_keys = consul.get_keys(datacenter="nyc1",
    keys=[consul.GetKeysKeyArgs(
        default="ami-1234",
        name="ami",
        path="service/app/launch_ami",
    )],
    token="abcd")
# Start our instance with the dynamic ami value
app_instance = aws.ec2.Instance("appInstance", ami=app_keys.var["ami"])
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as consul from "@pulumi/consul";

const appKeys = pulumi.output(consul.getKeys({
    datacenter: "nyc1",
    // Read the launch AMI from Consul
    keys: [{
        default: "ami-1234",
        name: "ami",
        path: "service/app/launch_ami",
    }],
    token: "abcd",
}, { async: true }));
// Start our instance with the dynamic ami value
const appInstance = new aws.ec2.Instance("app", {
    ami: appKeys.var.ami,
});

Using getKeys

function getKeys(args: GetKeysArgs, opts?: InvokeOptions): Promise<GetKeysResult>
def get_keys(datacenter: Optional[str] = None, keys: Optional[Sequence[GetKeysKeyArgs]] = None, namespace: Optional[str] = None, token: Optional[str] = None, opts: Optional[InvokeOptions] = None) -> GetKeysResult
func LookupKeys(ctx *Context, args *LookupKeysArgs, opts ...InvokeOption) (*LookupKeysResult, error)

Note: This function is named LookupKeys in the Go SDK.

public static class GetKeys {
    public static Task<GetKeysResult> InvokeAsync(GetKeysArgs args, InvokeOptions? opts = null)
}

The following arguments are supported:

Datacenter string

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

Keys List<GetKeysKeyArgs>

Specifies a key in Consul to be read. Supported values documented below. Multiple blocks supported.

Namespace string

The namespace to lookup the keys.

Token string

The ACL token to use. This overrides the token that the agent provides by default.

Datacenter string

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

Keys []GetKeysKey

Specifies a key in Consul to be read. Supported values documented below. Multiple blocks supported.

Namespace string

The namespace to lookup the keys.

Token string

The ACL token to use. This overrides the token that the agent provides by default.

datacenter string

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

keys GetKeysKey[]

Specifies a key in Consul to be read. Supported values documented below. Multiple blocks supported.

namespace string

The namespace to lookup the keys.

token string

The ACL token to use. This overrides the token that the agent provides by default.

datacenter str

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

keys Sequence[GetKeysKeyArgs]

Specifies a key in Consul to be read. Supported values documented below. Multiple blocks supported.

namespace str

The namespace to lookup the keys.

token str

The ACL token to use. This overrides the token that the agent provides by default.

getKeys Result

The following output properties are available:

Datacenter string

The datacenter the keys are being read from. * var.<name> - For each name given, the corresponding attribute has the value of the key.

Id string

The provider-assigned unique ID for this managed resource.

Var Dictionary<string, string>
Keys List<GetKeysKey>
Namespace string
Token string
Datacenter string

The datacenter the keys are being read from. * var.<name> - For each name given, the corresponding attribute has the value of the key.

Id string

The provider-assigned unique ID for this managed resource.

Var map[string]string
Keys []GetKeysKey
Namespace string
Token string
datacenter string

The datacenter the keys are being read from. * var.<name> - For each name given, the corresponding attribute has the value of the key.

id string

The provider-assigned unique ID for this managed resource.

var {[key: string]: string}
keys GetKeysKey[]
namespace string
token string
datacenter str

The datacenter the keys are being read from. * var.<name> - For each name given, the corresponding attribute has the value of the key.

id str

The provider-assigned unique ID for this managed resource.

var Mapping[str, str]
keys Sequence[GetKeysKey]
namespace str
token str

Supporting Types

GetKeysKey

Name string

This is the name of the key. This value of the key is exposed as var.<name>. This is not the path of the key in Consul.

Path string

This is the path in Consul that should be read or written to.

Default string

This is the default value to set for var.<name> if the key does not exist in Consul. Defaults to an empty string.

Name string

This is the name of the key. This value of the key is exposed as var.<name>. This is not the path of the key in Consul.

Path string

This is the path in Consul that should be read or written to.

Default string

This is the default value to set for var.<name> if the key does not exist in Consul. Defaults to an empty string.

name string

This is the name of the key. This value of the key is exposed as var.<name>. This is not the path of the key in Consul.

path string

This is the path in Consul that should be read or written to.

default string

This is the default value to set for var.<name> if the key does not exist in Consul. Defaults to an empty string.

name str

This is the name of the key. This value of the key is exposed as var.<name>. This is not the path of the key in Consul.

path str

This is the path in Consul that should be read or written to.

default str

This is the default value to set for var.<name> if the key does not exist in Consul. Defaults to an empty string.

Package Details

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