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

consul.getKeys

Explore with Pulumi AI

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

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

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    import * as consul from "@pulumi/consul";
    
    const appKeys = consul.getKeys({
        datacenter: "nyc1",
        keys: [{
            name: "ami",
            path: "service/app/launch_ami",
            "default": "ami-1234",
        }],
    });
    // Start our instance with the dynamic ami value
    const appInstance = new aws.ec2.Instance("appInstance", {ami: appKeys.then(appKeys => appKeys["var"]?.ami)});
    // ...
    
    import pulumi
    import pulumi_aws as aws
    import pulumi_consul as consul
    
    app_keys = consul.get_keys(datacenter="nyc1",
        keys=[consul.GetKeysKeyArgs(
            name="ami",
            path="service/app/launch_ami",
            default="ami-1234",
        )])
    # Start our instance with the dynamic ami value
    app_instance = aws.ec2.Instance("appInstance", ami=app_keys.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, &consul.LookupKeysArgs{
    			Datacenter: pulumi.StringRef("nyc1"),
    			Keys: []consul.GetKeysKey{
    				{
    					Name:    "ami",
    					Path:    "service/app/launch_ami",
    					Default: pulumi.StringRef("ami-1234"),
    				},
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		// Start our instance with the dynamic ami value
    		_, err = ec2.NewInstance(ctx, "appInstance", &ec2.InstanceArgs{
    			Ami: pulumi.String(appKeys.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 appKeys = Consul.GetKeys.Invoke(new()
        {
            Datacenter = "nyc1",
            Keys = new[]
            {
                new Consul.Inputs.GetKeysKeyInputArgs
                {
                    Name = "ami",
                    Path = "service/app/launch_ami",
                    Default = "ami-1234",
                },
            },
        });
    
        // Start our instance with the dynamic ami value
        var appInstance = new Aws.Ec2.Instance("appInstance", new()
        {
            Ami = appKeys.Apply(getKeysResult => getKeysResult.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.GetKeysArgs;
    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 appKeys = ConsulFunctions.getKeys(GetKeysArgs.builder()
                .datacenter("nyc1")
                .keys(GetKeysKeyArgs.builder()
                    .name("ami")
                    .path("service/app/launch_ami")
                    .default_("ami-1234")
                    .build())
                .build());
    
            var appInstance = new Instance("appInstance", InstanceArgs.builder()        
                .ami(appKeys.applyValue(getKeysResult -> getKeysResult.var().ami()))
                .build());
    
        }
    }
    
    resources:
      # Start our instance with the dynamic ami value
      appInstance:
        type: aws:ec2:Instance
        properties:
          ami: ${appKeys.var.ami}
    variables:
      appKeys:
        fn::invoke:
          Function: consul:getKeys
          Arguments:
            datacenter: nyc1
            keys:
              - name: ami
                path: service/app/launch_ami
                default: ami-1234
    

    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,
                 error_on_missing_keys: Optional[bool] = 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,
                 error_on_missing_keys: Optional[pulumi.Input[bool]] = 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.
    ErrorOnMissingKeys bool
    Whether to return an error when a key is absent from the KV store and no default is configured. This defaults to false.
    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.

    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 to use. This overrides the agent's default datacenter and the datacenter in the provider setup.
    ErrorOnMissingKeys bool
    Whether to return an error when a key is absent from the KV store and no default is configured. This defaults to false.
    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.

    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 to use. This overrides the agent's default datacenter and the datacenter in the provider setup.
    errorOnMissingKeys Boolean
    Whether to return an error when a key is absent from the KV store and no default is configured. This defaults to false.
    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.

    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 to use. This overrides the agent's default datacenter and the datacenter in the provider setup.
    errorOnMissingKeys boolean
    Whether to return an error when a key is absent from the KV store and no default is configured. This defaults to false.
    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.

    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 to use. This overrides the agent's default datacenter and the datacenter in the provider setup.
    error_on_missing_keys bool
    Whether to return an error when a key is absent from the KV store and no default is configured. This defaults to false.
    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.

    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 to use. This overrides the agent's default datacenter and the datacenter in the provider setup.
    errorOnMissingKeys Boolean
    Whether to return an error when a key is absent from the KV store and no default is configured. This defaults to false.
    keys List<Property Map>
    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.

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

    getKeys Result

    The following output properties are available:

    Datacenter string
    The datacenter to use. This overrides the agent's default datacenter and the datacenter in the provider setup.
    Id string
    The provider-assigned unique ID for this managed resource.
    Var Dictionary<string, string>
    For each name given, the corresponding attribute has the value of the key.
    ErrorOnMissingKeys bool
    Whether to return an error when a key is absent from the KV store and no default is configured. This defaults to false.
    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.

    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 to use. This overrides the agent's default datacenter and the datacenter in the provider setup.
    Id string
    The provider-assigned unique ID for this managed resource.
    Var map[string]string
    For each name given, the corresponding attribute has the value of the key.
    ErrorOnMissingKeys bool
    Whether to return an error when a key is absent from the KV store and no default is configured. This defaults to false.
    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.

    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 to use. This overrides the agent's default datacenter and the datacenter in the provider setup.
    id String
    The provider-assigned unique ID for this managed resource.
    var_ Map<String,String>
    For each name given, the corresponding attribute has the value of the key.
    errorOnMissingKeys Boolean
    Whether to return an error when a key is absent from the KV store and no default is configured. This defaults to false.
    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.

    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 to use. This overrides the agent's default datacenter and the datacenter in the provider setup.
    id string
    The provider-assigned unique ID for this managed resource.
    var {[key: string]: string}
    For each name given, the corresponding attribute has the value of the key.
    errorOnMissingKeys boolean
    Whether to return an error when a key is absent from the KV store and no default is configured. This defaults to false.
    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.

    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 to use. This overrides the agent's default datacenter and the datacenter in the provider setup.
    id str
    The provider-assigned unique ID for this managed resource.
    var Mapping[str, str]
    For each name given, the corresponding attribute has the value of the key.
    error_on_missing_keys bool
    Whether to return an error when a key is absent from the KV store and no default is configured. This defaults to false.
    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.

    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 to use. This overrides the agent's default datacenter and the datacenter in the provider setup.
    id String
    The provider-assigned unique ID for this managed resource.
    var Map<String>
    For each name given, the corresponding attribute has the value of the key.
    errorOnMissingKeys Boolean
    Whether to return an error when a key is absent from the KV store and no default is configured. This defaults to false.
    keys List<Property Map>
    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.

    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

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