Skip to content

Data Source: awsKeyPair

Use this data source to get information about a specific EC2 Key Pair.

Example Usage

The following example shows how to get a EC2 Key Pair including the public key material from its name.

import * as cdktf from "cdktf";
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const dataAwsKeyPairExample = new aws.dataAwsKeyPair.DataAwsKeyPair(
  this,
  "example",
  {
    filter: [
      {
        name: "tag:Component",
        values: ["web"],
      },
    ],
    includePublicKey: true,
    keyName: "test",
  }
);
new cdktf.TerraformOutput(this, "fingerprint", {
  value: dataAwsKeyPairExample.fingerprint,
});
new cdktf.TerraformOutput(this, "id", {
  value: dataAwsKeyPairExample.id,
});
new cdktf.TerraformOutput(this, "name", {
  value: dataAwsKeyPairExample.keyName,
});

Argument Reference

The arguments of this data source act as filters for querying the available Key Pairs. The given filters must match exactly one Key Pair whose data will be exported as attributes.

  • keyPairId - (Optional) Key Pair ID.
  • keyName - (Optional) Key Pair name.
  • includePublicKey - (Optional) Whether to include the public key material in the response.
  • filter - (Optional) Custom filter block as described below.

filter Configuration Block

The following arguments are supported by the filter configuration block:

  • name - (Required) Name of the filter field. Valid values can be found in the EC2 DescribeKeyPairs API Reference.
  • values - (Required) Set of values that are accepted for the given filter field. Results will be selected if any given value matches.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • id - ID of the Key Pair.
  • arn - ARN of the Key Pair.
  • createTime - Timestamp for when the key pair was created in ISO 8601 format.
  • fingerprint - SHA-1 digest of the DER encoded private key.
  • keyType - Type of key pair.
  • publicKey - Public key material.
  • tags - Any tags assigned to the Key Pair.

Timeouts

Configuration options:

  • read - (Default 20M)