HashiCorp Consul

Pulumi Official
Package maintained by Pulumi
v3.6.0 published on Tuesday, Apr 12, 2022 by Pulumi

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/v4/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 {
		appKeys, err := consul.LookupKeys(ctx, &GetKeysArgs{
			Datacenter: pulumi.StringRef("nyc1"),
			Keys: []GetKeysKey{
				GetKeysKey{
					Default: pulumi.StringRef("ami-1234"),
					Name:    "ami",
					Path:    "service/app/launch_ami",
				},
			},
			Token: pulumi.StringRef("abcd"),
		}, 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
	})
}

Coming soon!

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",
}));
// Start our instance with the dynamic ami value
const appInstance = new aws.ec2.Instance("app", {
    ami: appKeys.var.ami,
});

Coming soon!

Using getKeys

Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

function getKeys(args: GetKeysArgs, opts?: InvokeOptions): Promise<GetKeysResult>
function getKeysOutput(args: GetKeysOutputArgs, opts?: InvokeOptions): Output<GetKeysResult>
def get_keys(datacenter: Optional[str] = None,
             keys: Optional[Sequence[GetKeysKey]] = None,
             namespace: Optional[str] = None,
             partition: Optional[str] = None,
             token: Optional[str] = None,
             opts: Optional[InvokeOptions] = None) -> GetKeysResult
def get_keys_output(datacenter: Optional[pulumi.Input[str]] = None,
             keys: Optional[pulumi.Input[Sequence[pulumi.Input[GetKeysKeyArgs]]]] = None,
             namespace: Optional[pulumi.Input[str]] = None,
             partition: Optional[pulumi.Input[str]] = None,
             token: Optional[pulumi.Input[str]] = None,
             opts: Optional[InvokeOptions] = None) -> Output[GetKeysResult]
func LookupKeys(ctx *Context, args *LookupKeysArgs, opts ...InvokeOption) (*LookupKeysResult, error)
func LookupKeysOutput(ctx *Context, args *LookupKeysOutputArgs, opts ...InvokeOption) LookupKeysResultOutput

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

public static class GetKeys 
{
    public static Task<GetKeysResult> InvokeAsync(GetKeysArgs args, InvokeOptions? opts = null)
    public static Output<GetKeysResult> Invoke(GetKeysInvokeArgs args, InvokeOptions? opts = null)
}
public static CompletableFuture<GetKeysResult> getKeys(GetKeysArgs args, InvokeOptions options)
// Output-based functions aren't available in Java yet
Fn::Invoke:
  Function: consul:index/getKeys:getKeys
  Arguments:
    # Arguments dictionary

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<GetKeysKey>

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

Namespace string

The namespace to lookup the keys.

Partition string

The partition 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.

Partition string

The partition 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 ListKeysKey>

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

namespace String

The namespace to lookup the keys.

partition String

The partition 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.

partition string

The partition 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[GetKeysKey]

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

namespace str

The namespace to lookup the keys.

partition str

The partition to lookup the keys.

token str

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 List

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

namespace String

The namespace to lookup the keys.

partition String

The partition to lookup the keys.

token String

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
Partition 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
Partition 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
keys ListKeysKey>
namespace String
partition 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
partition 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
partition str
token str
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
keys List
namespace String
partition String
token String

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 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.

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.

Package Details

Repository
https://github.com/pulumi/pulumi-consul
License
Apache-2.0
Notes

This Pulumi package is based on the consul Terraform Provider.