1. Packages
  2. Consul Provider
  3. API Docs
  4. getKeyPrefix
Consul v3.12.2 published on Wednesday, Oct 16, 2024 by Pulumi

consul.getKeyPrefix

Explore with Pulumi AI

consul logo
Consul v3.12.2 published on Wednesday, Oct 16, 2024 by Pulumi

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    import * as consul from "@pulumi/consul";
    
    const app = consul.getKeyPrefix({
        datacenter: "nyc1",
        token: "abcd",
        pathPrefix: "myapp/config/",
        subkeyCollection: [{
            name: "ami",
            path: "app/launch_ami",
            "default": "ami-1234",
        }],
    });
    // Start our instance with the dynamic ami value
    const appInstance = new aws.index.Instance("app", {ami: app["var"]?.ami});
    
    import pulumi
    import pulumi_aws as aws
    import pulumi_consul as consul
    
    app = consul.get_key_prefix(datacenter="nyc1",
        token="abcd",
        path_prefix="myapp/config/",
        subkey_collection=[{
            "name": "ami",
            "path": "app/launch_ami",
            "default": "ami-1234",
        }])
    # Start our instance with the dynamic ami value
    app_instance = aws.index.Instance("app", ami=app.var.ami)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws"
    	"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 {
    		app, err := consul.LookupKeyPrefix(ctx, &consul.LookupKeyPrefixArgs{
    			Datacenter: pulumi.StringRef("nyc1"),
    			Token:      pulumi.StringRef("abcd"),
    			PathPrefix: "myapp/config/",
    			SubkeyCollection: []consul.GetKeyPrefixSubkeyCollection{
    				{
    					Name:    "ami",
    					Path:    "app/launch_ami",
    					Default: pulumi.StringRef("ami-1234"),
    				},
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		// Start our instance with the dynamic ami value
    		_, err = aws.NewInstance(ctx, "app", &aws.InstanceArgs{
    			Ami: app.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 app = Consul.GetKeyPrefix.Invoke(new()
        {
            Datacenter = "nyc1",
            Token = "abcd",
            PathPrefix = "myapp/config/",
            SubkeyCollection = new[]
            {
                new Consul.Inputs.GetKeyPrefixSubkeyCollectionInputArgs
                {
                    Name = "ami",
                    Path = "app/launch_ami",
                    Default = "ami-1234",
                },
            },
        });
    
        // Start our instance with the dynamic ami value
        var appInstance = new Aws.Index.Instance("app", new()
        {
            Ami = app.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.instance;
    import com.pulumi.aws.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 app = ConsulFunctions.getKeyPrefix(GetKeyPrefixArgs.builder()
                .datacenter("nyc1")
                .token("abcd")
                .pathPrefix("myapp/config/")
                .subkeyCollection(GetKeyPrefixSubkeyCollectionArgs.builder()
                    .name("ami")
                    .path("app/launch_ami")
                    .default_("ami-1234")
                    .build())
                .build());
    
            // Start our instance with the dynamic ami value
            var appInstance = new Instance("appInstance", InstanceArgs.builder()
                .ami(app.applyValue(getKeyPrefixResult -> getKeyPrefixResult.var().ami()))
                .build());
    
        }
    }
    
    resources:
      # Start our instance with the dynamic ami value
      appInstance:
        type: aws:instance
        name: app
        properties:
          ami: ${app.var.ami}
    variables:
      app:
        fn::invoke:
          Function: consul:getKeyPrefix
          Arguments:
            datacenter: nyc1
            token: abcd
            pathPrefix: myapp/config/
            subkeyCollection:
              - name: ami
                path: app/launch_ami
                default: ami-1234
    
    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    import * as consul from "@pulumi/consul";
    
    const web = consul.getKeyPrefix({
        datacenter: "nyc1",
        token: "efgh",
        pathPrefix: "myapp/config/",
    });
    // Start our instance with the dynamic ami value
    const webInstance = new aws.index.Instance("web", {ami: web.subkeys?.["app/launch_ami"]});
    
    import pulumi
    import pulumi_aws as aws
    import pulumi_consul as consul
    
    web = consul.get_key_prefix(datacenter="nyc1",
        token="efgh",
        path_prefix="myapp/config/")
    # Start our instance with the dynamic ami value
    web_instance = aws.index.Instance("web", ami=web.subkeys.app_launch_ami)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws"
    	"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 {
    		web, err := consul.LookupKeyPrefix(ctx, &consul.LookupKeyPrefixArgs{
    			Datacenter: pulumi.StringRef("nyc1"),
    			Token:      pulumi.StringRef("efgh"),
    			PathPrefix: "myapp/config/",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		// Start our instance with the dynamic ami value
    		_, err = aws.NewInstance(ctx, "web", &aws.InstanceArgs{
    			Ami: web.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 web = Consul.GetKeyPrefix.Invoke(new()
        {
            Datacenter = "nyc1",
            Token = "efgh",
            PathPrefix = "myapp/config/",
        });
    
        // Start our instance with the dynamic ami value
        var webInstance = new Aws.Index.Instance("web", new()
        {
            Ami = web.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.instance;
    import com.pulumi.aws.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 web = ConsulFunctions.getKeyPrefix(GetKeyPrefixArgs.builder()
                .datacenter("nyc1")
                .token("efgh")
                .pathPrefix("myapp/config/")
                .build());
    
            // Start our instance with the dynamic ami value
            var webInstance = new Instance("webInstance", InstanceArgs.builder()
                .ami(web.applyValue(getKeyPrefixResult -> getKeyPrefixResult.subkeys().app/launch_ami()))
                .build());
    
        }
    }
    
    resources:
      # Start our instance with the dynamic ami value
      webInstance:
        type: aws:instance
        name: web
        properties:
          ami: ${web.subkeys"app/launch_ami"[%!s(MISSING)]}
    variables:
      web:
        fn::invoke:
          Function: consul:getKeyPrefix
          Arguments:
            datacenter: nyc1
            token: efgh
            pathPrefix: myapp/config/
    

    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.12.2 published on Wednesday, Oct 16, 2024 by Pulumi