1. Packages
  2. Ibm Provider
  3. API Docs
  4. getResourceKey
ibm 1.77.1 published on Monday, Apr 14, 2025 by ibm-cloud

ibm.getResourceKey

Explore with Pulumi AI

Retrieve information about an existing IBM resource key from IBM Cloud as a read-only data source. For more information, about resource key, see ibmcloud resource service-keys.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as ibm from "@pulumi/ibm";

const resourceKeydata = ibm.getResourceKey({
    name: "myobjectKey",
    resourceInstanceId: ibm_resource_instance.resource.id,
});
Copy
import pulumi
import pulumi_ibm as ibm

resource_keydata = ibm.get_resource_key(name="myobjectKey",
    resource_instance_id=ibm_resource_instance["resource"]["id"])
Copy
package main

import (
	"github.com/pulumi/pulumi-terraform-provider/sdks/go/ibm/ibm"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := ibm.LookupResourceKey(ctx, &ibm.LookupResourceKeyArgs{
			Name:               "myobjectKey",
			ResourceInstanceId: pulumi.StringRef(ibm_resource_instance.Resource.Id),
		}, nil)
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Ibm = Pulumi.Ibm;

return await Deployment.RunAsync(() => 
{
    var resourceKeydata = Ibm.GetResourceKey.Invoke(new()
    {
        Name = "myobjectKey",
        ResourceInstanceId = ibm_resource_instance.Resource.Id,
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.ibm.IbmFunctions;
import com.pulumi.ibm.inputs.GetResourceKeyArgs;
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 resourceKeydata = IbmFunctions.getResourceKey(GetResourceKeyArgs.builder()
            .name("myobjectKey")
            .resourceInstanceId(ibm_resource_instance.resource().id())
            .build());

    }
}
Copy
variables:
  resourceKeydata:
    fn::invoke:
      function: ibm:getResourceKey
      arguments:
        name: myobjectKey
        resourceInstanceId: ${ibm_resource_instance.resource.id}
Copy

Example to access resource credentials using credentials attribute:

import * as pulumi from "@pulumi/pulumi";
import * as ibm from "@pulumi/ibm";

const key = ibm.getResourceKey({
    name: "myobjectKey",
    resourceInstanceId: ibm_resource_instance.resource.id,
});
export const accessKeyId = key.then(key => key.credentials?.["cos_hmac_keys.access_key_id"]);
export const secretAccessKey = key.then(key => key.credentials?.["cos_hmac_keys.secret_access_key"]);
Copy
import pulumi
import pulumi_ibm as ibm

key = ibm.get_resource_key(name="myobjectKey",
    resource_instance_id=ibm_resource_instance["resource"]["id"])
pulumi.export("accessKeyId", key.credentials["cos_hmac_keys.access_key_id"])
pulumi.export("secretAccessKey", key.credentials["cos_hmac_keys.secret_access_key"])
Copy
package main

import (
	"github.com/pulumi/pulumi-terraform-provider/sdks/go/ibm/ibm"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		key, err := ibm.LookupResourceKey(ctx, &ibm.LookupResourceKeyArgs{
			Name:               "myobjectKey",
			ResourceInstanceId: pulumi.StringRef(ibm_resource_instance.Resource.Id),
		}, nil)
		if err != nil {
			return err
		}
		ctx.Export("accessKeyId", key.Credentials.Cos_hmac_keys.access_key_id)
		ctx.Export("secretAccessKey", key.Credentials.Cos_hmac_keys.secret_access_key)
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Ibm = Pulumi.Ibm;

return await Deployment.RunAsync(() => 
{
    var key = Ibm.GetResourceKey.Invoke(new()
    {
        Name = "myobjectKey",
        ResourceInstanceId = ibm_resource_instance.Resource.Id,
    });

    return new Dictionary<string, object?>
    {
        ["accessKeyId"] = key.Apply(getResourceKeyResult => getResourceKeyResult.Credentials?.Cos_hmac_keys_access_key_id),
        ["secretAccessKey"] = key.Apply(getResourceKeyResult => getResourceKeyResult.Credentials?.Cos_hmac_keys_secret_access_key),
    };
});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.ibm.IbmFunctions;
import com.pulumi.ibm.inputs.GetResourceKeyArgs;
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 key = IbmFunctions.getResourceKey(GetResourceKeyArgs.builder()
            .name("myobjectKey")
            .resourceInstanceId(ibm_resource_instance.resource().id())
            .build());

        ctx.export("accessKeyId", key.applyValue(getResourceKeyResult -> getResourceKeyResult.credentials().cos_hmac_keys.access_key_id()));
        ctx.export("secretAccessKey", key.applyValue(getResourceKeyResult -> getResourceKeyResult.credentials().cos_hmac_keys.secret_access_key()));
    }
}
Copy
variables:
  key:
    fn::invoke:
      function: ibm:getResourceKey
      arguments:
        name: myobjectKey
        resourceInstanceId: ${ibm_resource_instance.resource.id}
outputs:
  accessKeyId: ${key.credentials"cos_hmac_keys.access_key_id"[%!s(MISSING)]}
  secretAccessKey: ${key.credentials"cos_hmac_keys.secret_access_key"[%!s(MISSING)]}
Copy

Using getResourceKey

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 getResourceKey(args: GetResourceKeyArgs, opts?: InvokeOptions): Promise<GetResourceKeyResult>
function getResourceKeyOutput(args: GetResourceKeyOutputArgs, opts?: InvokeOptions): Output<GetResourceKeyResult>
Copy
def get_resource_key(id: Optional[str] = None,
                     most_recent: Optional[bool] = None,
                     name: Optional[str] = None,
                     resource_alias_id: Optional[str] = None,
                     resource_instance_id: Optional[str] = None,
                     opts: Optional[InvokeOptions] = None) -> GetResourceKeyResult
def get_resource_key_output(id: Optional[pulumi.Input[str]] = None,
                     most_recent: Optional[pulumi.Input[bool]] = None,
                     name: Optional[pulumi.Input[str]] = None,
                     resource_alias_id: Optional[pulumi.Input[str]] = None,
                     resource_instance_id: Optional[pulumi.Input[str]] = None,
                     opts: Optional[InvokeOptions] = None) -> Output[GetResourceKeyResult]
Copy
func LookupResourceKey(ctx *Context, args *LookupResourceKeyArgs, opts ...InvokeOption) (*LookupResourceKeyResult, error)
func LookupResourceKeyOutput(ctx *Context, args *LookupResourceKeyOutputArgs, opts ...InvokeOption) LookupResourceKeyResultOutput
Copy

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

public static class GetResourceKey 
{
    public static Task<GetResourceKeyResult> InvokeAsync(GetResourceKeyArgs args, InvokeOptions? opts = null)
    public static Output<GetResourceKeyResult> Invoke(GetResourceKeyInvokeArgs args, InvokeOptions? opts = null)
}
Copy
public static CompletableFuture<GetResourceKeyResult> getResourceKey(GetResourceKeyArgs args, InvokeOptions options)
public static Output<GetResourceKeyResult> getResourceKey(GetResourceKeyArgs args, InvokeOptions options)
Copy
fn::invoke:
  function: ibm:index/getResourceKey:getResourceKey
  arguments:
    # arguments dictionary
Copy

The following arguments are supported:

Name This property is required. string
The name of the resource key. You can retrieve the value by executing the ibmcloud resource service-keys command in the IBM Cloud CLI.
Id string
(String) The unique identifier of the resource key.
MostRecent bool
If there are multiple resource keys, you can set this argument to true to import only the most recently created key.
ResourceAliasId string
The ID of the resource alias that the resource key is associated with. You can retrieve the value by executing the ibmcloud resource service-alias command in the IBM Cloud CLI. Note Conflicts with resource_instance_id.
ResourceInstanceId string
The ID of the resource instance that the resource key is associated with. You can retrieve the value by executing the ibmcloud resource service-instances command in the IBM Cloud CLI. Note: Conflicts with resource_alias_id.
Name This property is required. string
The name of the resource key. You can retrieve the value by executing the ibmcloud resource service-keys command in the IBM Cloud CLI.
Id string
(String) The unique identifier of the resource key.
MostRecent bool
If there are multiple resource keys, you can set this argument to true to import only the most recently created key.
ResourceAliasId string
The ID of the resource alias that the resource key is associated with. You can retrieve the value by executing the ibmcloud resource service-alias command in the IBM Cloud CLI. Note Conflicts with resource_instance_id.
ResourceInstanceId string
The ID of the resource instance that the resource key is associated with. You can retrieve the value by executing the ibmcloud resource service-instances command in the IBM Cloud CLI. Note: Conflicts with resource_alias_id.
name This property is required. String
The name of the resource key. You can retrieve the value by executing the ibmcloud resource service-keys command in the IBM Cloud CLI.
id String
(String) The unique identifier of the resource key.
mostRecent Boolean
If there are multiple resource keys, you can set this argument to true to import only the most recently created key.
resourceAliasId String
The ID of the resource alias that the resource key is associated with. You can retrieve the value by executing the ibmcloud resource service-alias command in the IBM Cloud CLI. Note Conflicts with resource_instance_id.
resourceInstanceId String
The ID of the resource instance that the resource key is associated with. You can retrieve the value by executing the ibmcloud resource service-instances command in the IBM Cloud CLI. Note: Conflicts with resource_alias_id.
name This property is required. string
The name of the resource key. You can retrieve the value by executing the ibmcloud resource service-keys command in the IBM Cloud CLI.
id string
(String) The unique identifier of the resource key.
mostRecent boolean
If there are multiple resource keys, you can set this argument to true to import only the most recently created key.
resourceAliasId string
The ID of the resource alias that the resource key is associated with. You can retrieve the value by executing the ibmcloud resource service-alias command in the IBM Cloud CLI. Note Conflicts with resource_instance_id.
resourceInstanceId string
The ID of the resource instance that the resource key is associated with. You can retrieve the value by executing the ibmcloud resource service-instances command in the IBM Cloud CLI. Note: Conflicts with resource_alias_id.
name This property is required. str
The name of the resource key. You can retrieve the value by executing the ibmcloud resource service-keys command in the IBM Cloud CLI.
id str
(String) The unique identifier of the resource key.
most_recent bool
If there are multiple resource keys, you can set this argument to true to import only the most recently created key.
resource_alias_id str
The ID of the resource alias that the resource key is associated with. You can retrieve the value by executing the ibmcloud resource service-alias command in the IBM Cloud CLI. Note Conflicts with resource_instance_id.
resource_instance_id str
The ID of the resource instance that the resource key is associated with. You can retrieve the value by executing the ibmcloud resource service-instances command in the IBM Cloud CLI. Note: Conflicts with resource_alias_id.
name This property is required. String
The name of the resource key. You can retrieve the value by executing the ibmcloud resource service-keys command in the IBM Cloud CLI.
id String
(String) The unique identifier of the resource key.
mostRecent Boolean
If there are multiple resource keys, you can set this argument to true to import only the most recently created key.
resourceAliasId String
The ID of the resource alias that the resource key is associated with. You can retrieve the value by executing the ibmcloud resource service-alias command in the IBM Cloud CLI. Note Conflicts with resource_instance_id.
resourceInstanceId String
The ID of the resource instance that the resource key is associated with. You can retrieve the value by executing the ibmcloud resource service-instances command in the IBM Cloud CLI. Note: Conflicts with resource_alias_id.

getResourceKey Result

The following output properties are available:

Credentials Dictionary<string, string>
(Map) The credentials associated with the key.
CredentialsJson string
(String) The credentials associated with the key in json format.
Crn string
(String) CRN of resource key.
Id string
(String) The unique identifier of the resource key.
Name string
OnetimeCredentials bool
(Bool) A boolean that dictates if the onetime_credentials is true or false.
Role string
(String) The user role.
Status string
(String) The status of the resource key.
MostRecent bool
ResourceAliasId string
ResourceInstanceId string
Credentials map[string]string
(Map) The credentials associated with the key.
CredentialsJson string
(String) The credentials associated with the key in json format.
Crn string
(String) CRN of resource key.
Id string
(String) The unique identifier of the resource key.
Name string
OnetimeCredentials bool
(Bool) A boolean that dictates if the onetime_credentials is true or false.
Role string
(String) The user role.
Status string
(String) The status of the resource key.
MostRecent bool
ResourceAliasId string
ResourceInstanceId string
credentials Map<String,String>
(Map) The credentials associated with the key.
credentialsJson String
(String) The credentials associated with the key in json format.
crn String
(String) CRN of resource key.
id String
(String) The unique identifier of the resource key.
name String
onetimeCredentials Boolean
(Bool) A boolean that dictates if the onetime_credentials is true or false.
role String
(String) The user role.
status String
(String) The status of the resource key.
mostRecent Boolean
resourceAliasId String
resourceInstanceId String
credentials {[key: string]: string}
(Map) The credentials associated with the key.
credentialsJson string
(String) The credentials associated with the key in json format.
crn string
(String) CRN of resource key.
id string
(String) The unique identifier of the resource key.
name string
onetimeCredentials boolean
(Bool) A boolean that dictates if the onetime_credentials is true or false.
role string
(String) The user role.
status string
(String) The status of the resource key.
mostRecent boolean
resourceAliasId string
resourceInstanceId string
credentials Mapping[str, str]
(Map) The credentials associated with the key.
credentials_json str
(String) The credentials associated with the key in json format.
crn str
(String) CRN of resource key.
id str
(String) The unique identifier of the resource key.
name str
onetime_credentials bool
(Bool) A boolean that dictates if the onetime_credentials is true or false.
role str
(String) The user role.
status str
(String) The status of the resource key.
most_recent bool
resource_alias_id str
resource_instance_id str
credentials Map<String>
(Map) The credentials associated with the key.
credentialsJson String
(String) The credentials associated with the key in json format.
crn String
(String) CRN of resource key.
id String
(String) The unique identifier of the resource key.
name String
onetimeCredentials Boolean
(Bool) A boolean that dictates if the onetime_credentials is true or false.
role String
(String) The user role.
status String
(String) The status of the resource key.
mostRecent Boolean
resourceAliasId String
resourceInstanceId String

Package Details

Repository
ibm ibm-cloud/terraform-provider-ibm
License
Notes
This Pulumi package is based on the ibm Terraform Provider.