HashiCorp Consul

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

getKeyPrefix

Example Usage

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

class MyStack : Stack
{
    public MyStack()
    {
        var appKeyPrefix = Output.Create(Consul.GetKeyPrefix.InvokeAsync(new Consul.GetKeyPrefixArgs
        {
            Datacenter = "nyc1",
            PathPrefix = "myapp/config/",
            SubkeyCollection = 
            {
                new Consul.Inputs.GetKeyPrefixSubkeyCollectionArgs
                {
                    Default = "ami-1234",
                    Name = "ami",
                    Path = "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 = appKeyPrefix.Apply(appKeyPrefix => appKeyPrefix.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 {
		appKeyPrefix, err := consul.LookupKeyPrefix(ctx, &GetKeyPrefixArgs{
			Datacenter: pulumi.StringRef("nyc1"),
			PathPrefix: "myapp/config/",
			SubkeyCollection: []GetKeyPrefixSubkeyCollection{
				GetKeyPrefixSubkeyCollection{
					Default: pulumi.StringRef("ami-1234"),
					Name:    "ami",
					Path:    "app/launch_ami",
				},
			},
			Token: pulumi.StringRef("abcd"),
		}, nil)
		if err != nil {
			return err
		}
		_, err = ec2.NewInstance(ctx, "appInstance", &ec2.InstanceArgs{
			Ami: pulumi.String(appKeyPrefix.Var.Ami),
		})
		if err != nil {
			return err
		}
		return nil
	})
}

Coming soon!

import pulumi
import pulumi_aws as aws
import pulumi_consul as consul

app_key_prefix = consul.get_key_prefix(datacenter="nyc1",
    path_prefix="myapp/config/",
    subkey_collection=[consul.GetKeyPrefixSubkeyCollectionArgs(
        default="ami-1234",
        name="ami",
        path="app/launch_ami",
    )],
    token="abcd")
# Start our instance with the dynamic ami value
app_instance = aws.ec2.Instance("appInstance", ami=app_key_prefix.var["ami"])
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as consul from "@pulumi/consul";

const appKeyPrefix = pulumi.output(consul.getKeyPrefix({
    datacenter: "nyc1",
    // Prefix to add to prepend to all of the subkey names below.
    pathPrefix: "myapp/config/",
    // Read the ami subkey
    subkeyCollection: [{
        default: "ami-1234",
        name: "ami",
        path: "app/launch_ami",
    }],
    token: "abcd",
}));
// Start our instance with the dynamic ami value
const appInstance = new aws.ec2.Instance("app", {
    ami: appKeyPrefix.var.ami,
});

Coming soon!

Using getKeyPrefix

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 getKeyPrefix(args: GetKeyPrefixArgs, opts?: InvokeOptions): Promise<GetKeyPrefixResult>
function getKeyPrefixOutput(args: GetKeyPrefixOutputArgs, opts?: InvokeOptions): Output<GetKeyPrefixResult>
def get_key_prefix(datacenter: Optional[str] = None,
                   namespace: Optional[str] = None,
                   partition: Optional[str] = None,
                   path_prefix: Optional[str] = None,
                   subkey_collection: Optional[Sequence[GetKeyPrefixSubkeyCollection]] = None,
                   token: Optional[str] = None,
                   opts: Optional[InvokeOptions] = None) -> GetKeyPrefixResult
def get_key_prefix_output(datacenter: Optional[pulumi.Input[str]] = None,
                   namespace: Optional[pulumi.Input[str]] = None,
                   partition: Optional[pulumi.Input[str]] = None,
                   path_prefix: Optional[pulumi.Input[str]] = None,
                   subkey_collection: Optional[pulumi.Input[Sequence[pulumi.Input[GetKeyPrefixSubkeyCollectionArgs]]]] = None,
                   token: Optional[pulumi.Input[str]] = None,
                   opts: Optional[InvokeOptions] = None) -> Output[GetKeyPrefixResult]
func LookupKeyPrefix(ctx *Context, args *LookupKeyPrefixArgs, opts ...InvokeOption) (*LookupKeyPrefixResult, error)
func LookupKeyPrefixOutput(ctx *Context, args *LookupKeyPrefixOutputArgs, opts ...InvokeOption) LookupKeyPrefixResultOutput

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

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

The following arguments are supported:

PathPrefix string

Specifies the common prefix shared by all keys that will be read by this data source instance. In most cases, this will end with a slash to read a "folder" of subkeys.

Datacenter string

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

Namespace string

The namespace to lookup the keys within.

Partition string

The namespace to lookup the keys within.

SubkeyCollection List<GetKeyPrefixSubkeyCollection>

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

Token string

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

PathPrefix string

Specifies the common prefix shared by all keys that will be read by this data source instance. In most cases, this will end with a slash to read a "folder" of subkeys.

Datacenter string

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

Namespace string

The namespace to lookup the keys within.

Partition string

The namespace to lookup the keys within.

SubkeyCollection []GetKeyPrefixSubkeyCollection

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

Token string

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

pathPrefix String

Specifies the common prefix shared by all keys that will be read by this data source instance. In most cases, this will end with a slash to read a "folder" of subkeys.

datacenter String

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

namespace String

The namespace to lookup the keys within.

partition String

The namespace to lookup the keys within.

subkeyCollection List<GetKeyPrefixSubkeyCollection>

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

token String

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

pathPrefix string

Specifies the common prefix shared by all keys that will be read by this data source instance. In most cases, this will end with a slash to read a "folder" of subkeys.

datacenter string

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

namespace string

The namespace to lookup the keys within.

partition string

The namespace to lookup the keys within.

subkeyCollection GetKeyPrefixSubkeyCollection[]

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

token string

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

path_prefix str

Specifies the common prefix shared by all keys that will be read by this data source instance. In most cases, this will end with a slash to read a "folder" of subkeys.

datacenter str

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

namespace str

The namespace to lookup the keys within.

partition str

The namespace to lookup the keys within.

subkey_collection Sequence[GetKeyPrefixSubkeyCollection]

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

token str

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

pathPrefix String

Specifies the common prefix shared by all keys that will be read by this data source instance. In most cases, this will end with a slash to read a "folder" of subkeys.

datacenter String

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

namespace String

The namespace to lookup the keys within.

partition String

The namespace to lookup the keys within.

subkeyCollection List<Property Map>

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

token String

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

getKeyPrefix Result

The following output properties are available:

Datacenter string

The datacenter the keys are being read from.

Id string

The provider-assigned unique ID for this managed resource.

PathPrefix string

the common prefix shared by all keys being read.

  • var.<name> - For each name given, the corresponding attribute has the value of the key.
Subkeys Dictionary<string, string>

A map of the subkeys and values is set if no subkey block is provided.

Var Dictionary<string, string>
Namespace string
Partition string
SubkeyCollection List<GetKeyPrefixSubkeyCollection>
Token string
Datacenter string

The datacenter the keys are being read from.

Id string

The provider-assigned unique ID for this managed resource.

PathPrefix string

the common prefix shared by all keys being read.

  • var.<name> - For each name given, the corresponding attribute has the value of the key.
Subkeys map[string]string

A map of the subkeys and values is set if no subkey block is provided.

Var map[string]string
Namespace string
Partition string
SubkeyCollection []GetKeyPrefixSubkeyCollection
Token string
datacenter String

The datacenter the keys are being read from.

id String

The provider-assigned unique ID for this managed resource.

pathPrefix String

the common prefix shared by all keys being read.

  • var.<name> - For each name given, the corresponding attribute has the value of the key.
subkeys Map<String,String>

A map of the subkeys and values is set if no subkey block is provided.

var_ Map<String,String>
namespace String
partition String
subkeyCollection List<GetKeyPrefixSubkeyCollection>
token String
datacenter string

The datacenter the keys are being read from.

id string

The provider-assigned unique ID for this managed resource.

pathPrefix string

the common prefix shared by all keys being read.

  • var.<name> - For each name given, the corresponding attribute has the value of the key.
subkeys {[key: string]: string}

A map of the subkeys and values is set if no subkey block is provided.

var {[key: string]: string}
namespace string
partition string
subkeyCollection GetKeyPrefixSubkeyCollection[]
token string
datacenter str

The datacenter the keys are being read from.

id str

The provider-assigned unique ID for this managed resource.

path_prefix str

the common prefix shared by all keys being read.

  • var.<name> - For each name given, the corresponding attribute has the value of the key.
subkeys Mapping[str, str]

A map of the subkeys and values is set if no subkey block is provided.

var Mapping[str, str]
namespace str
partition str
subkey_collection Sequence[GetKeyPrefixSubkeyCollection]
token str
datacenter String

The datacenter the keys are being read from.

id String

The provider-assigned unique ID for this managed resource.

pathPrefix String

the common prefix shared by all keys being read.

  • var.<name> - For each name given, the corresponding attribute has the value of the key.
subkeys Map<String>

A map of the subkeys and values is set if no subkey block is provided.

var Map<String>
namespace String
partition String
subkeyCollection List<Property Map>
token String

Supporting Types

GetKeyPrefixSubkeyCollection

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 subkey in Consul.

Path string

This is the subkey path in Consul (which will be appended to the given path_prefix) to construct the full key that will be used to read the value.

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 subkey in Consul.

Path string

This is the subkey path in Consul (which will be appended to the given path_prefix) to construct the full key that will be used to read the value.

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 subkey in Consul.

path String

This is the subkey path in Consul (which will be appended to the given path_prefix) to construct the full key that will be used to read the value.

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 subkey in Consul.

path string

This is the subkey path in Consul (which will be appended to the given path_prefix) to construct the full key that will be used to read the value.

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 subkey in Consul.

path str

This is the subkey path in Consul (which will be appended to the given path_prefix) to construct the full key that will be used to read the value.

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 subkey in Consul.

path String

This is the subkey path in Consul (which will be appended to the given path_prefix) to construct the full key that will be used to read the value.

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.