getKeyPair

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.

package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.Ec2Functions;
import com.pulumi.aws.ec2.inputs.GetKeyPairArgs;
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 example = Ec2Functions.getKeyPair(GetKeyPairArgs.builder()
.keyName("test")
.includePublicKey(true)
.filters(GetKeyPairFilterArgs.builder()
.name("tag:Component")
.values("web")
.build())
.build());
ctx.export("fingerprint", example.applyValue(getKeyPairResult -> getKeyPairResult.fingerprint()));
ctx.export("name", example.applyValue(getKeyPairResult -> getKeyPairResult.keyName()));
ctx.export("id", example.applyValue(getKeyPairResult -> getKeyPairResult.id()));
}
}

Return

A collection of values returned by getKeyPair.

Parameters

argument

A collection of arguments for invoking getKeyPair.


suspend fun getKeyPair(filters: List<GetKeyPairFilter>? = null, includePublicKey: Boolean? = null, keyName: String? = null, keyPairId: String? = null, tags: Map<String, String>? = null): GetKeyPairResult

Return

A collection of values returned by getKeyPair.

Parameters

filters

Custom filter block as described below.

includePublicKey

Whether to include the public key material in the response.

keyName

Key Pair name.

keyPairId

Key Pair ID.

tags

Any tags assigned to the Key Pair.

See also


suspend fun getKeyPair(argument: suspend GetKeyPairPlainArgsBuilder.() -> Unit): GetKeyPairResult

Return

A collection of values returned by getKeyPair.

Parameters

argument

Builder for com.pulumi.aws.ec2.kotlin.inputs.GetKeyPairPlainArgs.

See also