1. Packages
  2. HashiCorp Consul
  3. API Docs
  4. getKeyPrefix
Consul v3.11.2 published on Thursday, Mar 21, 2024 by Pulumi

consul.getKeyPrefix

Explore with Pulumi AI

consul logo
Consul v3.11.2 published on Thursday, Mar 21, 2024 by Pulumi

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    import * as consul from "@pulumi/consul";
    
    const appKeyPrefix = consul.getKeyPrefix({
        datacenter: "nyc1",
        pathPrefix: "myapp/config/",
        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("appInstance", {ami: appKeyPrefix.then(appKeyPrefix => appKeyPrefix["var"]?.ami)});
    
    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"])
    
    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, &consul.LookupKeyPrefixArgs{
    			Datacenter: pulumi.StringRef("nyc1"),
    			PathPrefix: "myapp/config/",
    			SubkeyCollection: []consul.GetKeyPrefixSubkeyCollection{
    				{
    					Default: pulumi.StringRef("ami-1234"),
    					Name:    "ami",
    					Path:    "app/launch_ami",
    				},
    			},
    			Token: pulumi.StringRef("abcd"),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		// Start our instance with the dynamic ami value
    		_, err = ec2.NewInstance(ctx, "appInstance", &ec2.InstanceArgs{
    			Ami: pulumi.String(appKeyPrefix.Var.Ami),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    using Consul = Pulumi.Consul;
    
    return await Deployment.RunAsync(() => 
    {
        var appKeyPrefix = Consul.GetKeyPrefix.Invoke(new()
        {
            Datacenter = "nyc1",
            PathPrefix = "myapp/config/",
            SubkeyCollection = new[]
            {
                new Consul.Inputs.GetKeyPrefixSubkeyCollectionInputArgs
                {
                    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()
        {
            Ami = appKeyPrefix.Apply(getKeyPrefixResult => getKeyPrefixResult.Var?.Ami),
        });
    
    });
    
    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.GetKeyPrefixArgs;
    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) {
            final var appKeyPrefix = ConsulFunctions.getKeyPrefix(GetKeyPrefixArgs.builder()
                .datacenter("nyc1")
                .pathPrefix("myapp/config/")
                .subkeyCollection(GetKeyPrefixSubkeyCollectionArgs.builder()
                    .default_("ami-1234")
                    .name("ami")
                    .path("app/launch_ami")
                    .build())
                .token("abcd")
                .build());
    
            var appInstance = new Instance("appInstance", InstanceArgs.builder()        
                .ami(appKeyPrefix.applyValue(getKeyPrefixResult -> getKeyPrefixResult.var().ami()))
                .build());
    
        }
    }
    
    resources:
      # Start our instance with the dynamic ami value
      appInstance:
        type: aws:ec2:Instance
        properties:
          ami: ${appKeyPrefix.var.ami}
    variables:
      appKeyPrefix:
        fn::invoke:
          Function: consul:getKeyPrefix
          Arguments:
            datacenter: nyc1
            pathPrefix: myapp/config/
            subkeyCollection:
              - default: ami-1234
                name: ami
                path: app/launch_ami
            token: abcd
    
    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    import * as consul from "@pulumi/consul";
    
    const webKeyPrefix = consul.getKeyPrefix({
        datacenter: "nyc1",
        pathPrefix: "myapp/config/",
        token: "efgh",
    });
    // Start our instance with the dynamic ami value
    const webInstance = new aws.ec2.Instance("webInstance", {ami: webKeyPrefix.then(webKeyPrefix => webKeyPrefix.subkeys?.["app/launch_ami"])});
    
    import pulumi
    import pulumi_aws as aws
    import pulumi_consul as consul
    
    web_key_prefix = consul.get_key_prefix(datacenter="nyc1",
        path_prefix="myapp/config/",
        token="efgh")
    # Start our instance with the dynamic ami value
    web_instance = aws.ec2.Instance("webInstance", ami=web_key_prefix.subkeys["app/launch_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 {
    		webKeyPrefix, err := consul.LookupKeyPrefix(ctx, &consul.LookupKeyPrefixArgs{
    			Datacenter: pulumi.StringRef("nyc1"),
    			PathPrefix: "myapp/config/",
    			Token:      pulumi.StringRef("efgh"),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		// Start our instance with the dynamic ami value
    		_, err = ec2.NewInstance(ctx, "webInstance", &ec2.InstanceArgs{
    			Ami: pulumi.String(webKeyPrefix.Subkeys.App / launch_ami),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    using Consul = Pulumi.Consul;
    
    return await Deployment.RunAsync(() => 
    {
        var webKeyPrefix = Consul.GetKeyPrefix.Invoke(new()
        {
            Datacenter = "nyc1",
            PathPrefix = "myapp/config/",
            Token = "efgh",
        });
    
        // Start our instance with the dynamic ami value
        var webInstance = new Aws.Ec2.Instance("webInstance", new()
        {
            Ami = webKeyPrefix.Apply(getKeyPrefixResult => getKeyPrefixResult.Subkeys?.App_launch_ami),
        });
    
    });
    
    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.GetKeyPrefixArgs;
    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) {
            final var webKeyPrefix = ConsulFunctions.getKeyPrefix(GetKeyPrefixArgs.builder()
                .datacenter("nyc1")
                .pathPrefix("myapp/config/")
                .token("efgh")
                .build());
    
            var webInstance = new Instance("webInstance", InstanceArgs.builder()        
                .ami(webKeyPrefix.applyValue(getKeyPrefixResult -> getKeyPrefixResult.subkeys().app/launch_ami()))
                .build());
    
        }
    }
    
    resources:
      # Start our instance with the dynamic ami value
      webInstance:
        type: aws:ec2:Instance
        properties:
          ami: ${webKeyPrefix.subkeys"app/launch_ami"[%!s(MISSING)]}
    variables:
      webKeyPrefix:
        fn::invoke:
          Function: consul:getKeyPrefix
          Arguments:
            datacenter: nyc1
            pathPrefix: myapp/config/
            token: efgh
    

    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.

    Deprecated: The token argument has been deprecated and will be removed in a future release. Please use the token argument in the provider configuration

    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.

    Deprecated: The token argument has been deprecated and will be removed in a future release. Please use the token argument in the provider configuration

    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.

    Deprecated: The token argument has been deprecated and will be removed in a future release. Please use the token argument in the provider configuration

    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.

    Deprecated: The token argument has been deprecated and will be removed in a future release. Please use the token argument in the provider configuration

    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.

    Deprecated: The token argument has been deprecated and will be removed in a future release. Please use the token argument in the provider configuration

    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.

    Deprecated: The token argument has been deprecated and will be removed in a future release. Please use the token argument in the provider configuration

    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

    Deprecated: The token argument has been deprecated and will be removed in a future release. Please use the token argument in the provider configuration

    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

    Deprecated: The token argument has been deprecated and will be removed in a future release. Please use the token argument in the provider configuration

    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

    Deprecated: The token argument has been deprecated and will be removed in a future release. Please use the token argument in the provider configuration

    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

    Deprecated: The token argument has been deprecated and will be removed in a future release. Please use the token argument in the provider configuration

    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

    Deprecated: The token argument has been deprecated and will be removed in a future release. Please use the token argument in the provider configuration

    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

    Deprecated: The token argument has been deprecated and will be removed in a future release. Please use the token argument in the provider configuration

    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
    HashiCorp Consul pulumi/pulumi-consul
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the consul Terraform Provider.
    consul logo
    Consul v3.11.2 published on Thursday, Mar 21, 2024 by Pulumi