@pulumi/aws-native
Version:
The Pulumi AWS Cloud Control Provider enables you to build, deploy, and manage [any AWS resource that's supported by the AWS Cloud Control API](https://github.com/pulumi/pulumi-aws-native/blob/master/provider/cmd/pulumi-gen-aws-native/supported-types.txt)
139 lines • 6.1 kB
JavaScript
;
// *** WARNING: this file was generated by pulumi-language-nodejs. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
Object.defineProperty(exports, "__esModule", { value: true });
exports.KeyPair = void 0;
const pulumi = require("@pulumi/pulumi");
const utilities = require("../utilities");
/**
* Specifies a key pair for use with an EC2long instance as follows:
* + To import an existing key pair, include the ``PublicKeyMaterial`` property.
* + To create a new key pair, omit the ``PublicKeyMaterial`` property.
*
* When you import an existing key pair, you specify the public key material for the key. We assume that you have the private key material for the key. CFNlong does not create or return the private key material when you import a key pair.
* When you create a new key pair, the private key is saved to SYSlong Parameter Store, using a parameter with the following name: ``/ec2/keypair/{key_pair_id}``. For more information about retrieving private key, and the required permissions, see [Create a key pair using](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/create-key-pairs.html#create-key-pair-cloudformation) in the *User Guide*.
* When CFN deletes a key pair that was created or imported by a stack, it also deletes the parameter that was used to store the private key material in Parameter Store.
*
* ## Example Usage
* ### Example
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws_native from "@pulumi/aws-native";
*
* const newKeyPair = new aws_native.ec2.KeyPair("newKeyPair", {keyName: "MyKeyPair"});
* const ec2Instance = new aws_native.ec2.Instance("ec2Instance", {
* imageId: "ami-02b92c281a4d3dc79",
* keyName: newKeyPair.id,
* });
*
* ```
* ### Example
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws_native from "@pulumi/aws-native";
*
* const newKeyPair = new aws_native.ec2.KeyPair("newKeyPair", {keyName: "MyKeyPair"});
* const ec2Instance = new aws_native.ec2.Instance("ec2Instance", {
* imageId: "ami-02b92c281a4d3dc79",
* keyName: newKeyPair.id,
* });
*
* ```
* ### Example
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws_native from "@pulumi/aws-native";
*
* const importedKeyPair = new aws_native.ec2.KeyPair("importedKeyPair", {
* keyName: "NameForMyImportedKeyPair",
* publicKeyMaterial: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICfp1F7DhdWZdqkYAUGCzcBsLmJeu9izpIyGpmmg7eCz example",
* });
* const ec2Instance = new aws_native.ec2.Instance("ec2Instance", {
* imageId: "ami-02b92c281a4d3dc79",
* keyName: importedKeyPair.id,
* });
*
* ```
* ### Example
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws_native from "@pulumi/aws-native";
*
* const importedKeyPair = new aws_native.ec2.KeyPair("importedKeyPair", {
* keyName: "NameForMyImportedKeyPair",
* publicKeyMaterial: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICfp1F7DhdWZdqkYAUGCzcBsLmJeu9izpIyGpmmg7eCz example",
* });
* const ec2Instance = new aws_native.ec2.Instance("ec2Instance", {
* imageId: "ami-02b92c281a4d3dc79",
* keyName: importedKeyPair.id,
* });
*
* ```
*/
class KeyPair extends pulumi.CustomResource {
/**
* Get an existing KeyPair resource's state with the given name, ID, and optional extra
* properties used to qualify the lookup.
*
* @param name The _unique_ name of the resulting resource.
* @param id The _unique_ provider ID of the resource to lookup.
* @param opts Optional settings to control the behavior of the CustomResource.
*/
static get(name, id, opts) {
return new KeyPair(name, undefined, { ...opts, id: id });
}
/**
* Returns true if the given object is an instance of KeyPair. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
static isInstance(obj) {
if (obj === undefined || obj === null) {
return false;
}
return obj['__pulumiType'] === KeyPair.__pulumiType;
}
/**
* Create a KeyPair resource with the given unique name, arguments, and options.
*
* @param name The _unique_ name of the resource.
* @param args The arguments to use to populate this resource's properties.
* @param opts A bag of options that control this resource's behavior.
*/
constructor(name, args, opts) {
let resourceInputs = {};
opts = opts || {};
if (!opts.id) {
if (args?.keyName === undefined && !opts.urn) {
throw new Error("Missing required property 'keyName'");
}
resourceInputs["keyFormat"] = args?.keyFormat;
resourceInputs["keyName"] = args?.keyName;
resourceInputs["keyType"] = args?.keyType;
resourceInputs["publicKeyMaterial"] = args?.publicKeyMaterial;
resourceInputs["tags"] = args?.tags;
resourceInputs["keyFingerprint"] = undefined /*out*/;
resourceInputs["keyPairId"] = undefined /*out*/;
}
else {
resourceInputs["keyFingerprint"] = undefined /*out*/;
resourceInputs["keyFormat"] = undefined /*out*/;
resourceInputs["keyName"] = undefined /*out*/;
resourceInputs["keyPairId"] = undefined /*out*/;
resourceInputs["keyType"] = undefined /*out*/;
resourceInputs["publicKeyMaterial"] = undefined /*out*/;
resourceInputs["tags"] = undefined /*out*/;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
const replaceOnChanges = { replaceOnChanges: ["keyFormat", "keyName", "keyType", "publicKeyMaterial", "tags[*]"] };
opts = pulumi.mergeOptions(opts, replaceOnChanges);
super(KeyPair.__pulumiType, name, resourceInputs, opts);
}
}
exports.KeyPair = KeyPair;
/** @internal */
KeyPair.__pulumiType = 'aws-native:ec2:KeyPair';
//# sourceMappingURL=keyPair.js.map