1. Packages
  2. Alibaba Cloud Provider
  3. API Docs
  4. ecs
  5. EcsKeyPair
Alibaba Cloud v3.76.0 published on Tuesday, Apr 8, 2025 by Pulumi

alicloud.ecs.EcsKeyPair

Explore with Pulumi AI

Provides a ECS Key Pair resource.

For information about ECS Key Pair and how to use it, see What is Key Pair.

NOTE: Available since v1.121.0.

Example Usage

Basic Usage

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

const example = new alicloud.ecs.EcsKeyPair("example", {keyPairName: "key_pair_name"});
// Using name prefix to build key pair
const prefix = new alicloud.ecs.EcsKeyPair("prefix", {keyNamePrefix: "terraform-test-key-pair-prefix"});
// Import an existing public key to build a alicloud key pair
const publickey = new alicloud.ecs.EcsKeyPair("publickey", {
    keyPairName: "my_public_key",
    publicKey: "ssh-rsa AAAAB3Nza12345678qwertyuudsfsg",
});
Copy
import pulumi
import pulumi_alicloud as alicloud

example = alicloud.ecs.EcsKeyPair("example", key_pair_name="key_pair_name")
# Using name prefix to build key pair
prefix = alicloud.ecs.EcsKeyPair("prefix", key_name_prefix="terraform-test-key-pair-prefix")
# Import an existing public key to build a alicloud key pair
publickey = alicloud.ecs.EcsKeyPair("publickey",
    key_pair_name="my_public_key",
    public_key="ssh-rsa AAAAB3Nza12345678qwertyuudsfsg")
Copy
package main

import (
	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/ecs"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := ecs.NewEcsKeyPair(ctx, "example", &ecs.EcsKeyPairArgs{
			KeyPairName: pulumi.String("key_pair_name"),
		})
		if err != nil {
			return err
		}
		// Using name prefix to build key pair
		_, err = ecs.NewEcsKeyPair(ctx, "prefix", &ecs.EcsKeyPairArgs{
			KeyNamePrefix: pulumi.String("terraform-test-key-pair-prefix"),
		})
		if err != nil {
			return err
		}
		// Import an existing public key to build a alicloud key pair
		_, err = ecs.NewEcsKeyPair(ctx, "publickey", &ecs.EcsKeyPairArgs{
			KeyPairName: pulumi.String("my_public_key"),
			PublicKey:   pulumi.String("ssh-rsa AAAAB3Nza12345678qwertyuudsfsg"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using AliCloud = Pulumi.AliCloud;

return await Deployment.RunAsync(() => 
{
    var example = new AliCloud.Ecs.EcsKeyPair("example", new()
    {
        KeyPairName = "key_pair_name",
    });

    // Using name prefix to build key pair
    var prefix = new AliCloud.Ecs.EcsKeyPair("prefix", new()
    {
        KeyNamePrefix = "terraform-test-key-pair-prefix",
    });

    // Import an existing public key to build a alicloud key pair
    var publickey = new AliCloud.Ecs.EcsKeyPair("publickey", new()
    {
        KeyPairName = "my_public_key",
        PublicKey = "ssh-rsa AAAAB3Nza12345678qwertyuudsfsg",
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.alicloud.ecs.EcsKeyPair;
import com.pulumi.alicloud.ecs.EcsKeyPairArgs;
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) {
        var example = new EcsKeyPair("example", EcsKeyPairArgs.builder()
            .keyPairName("key_pair_name")
            .build());

        // Using name prefix to build key pair
        var prefix = new EcsKeyPair("prefix", EcsKeyPairArgs.builder()
            .keyNamePrefix("terraform-test-key-pair-prefix")
            .build());

        // Import an existing public key to build a alicloud key pair
        var publickey = new EcsKeyPair("publickey", EcsKeyPairArgs.builder()
            .keyPairName("my_public_key")
            .publicKey("ssh-rsa AAAAB3Nza12345678qwertyuudsfsg")
            .build());

    }
}
Copy
resources:
  example:
    type: alicloud:ecs:EcsKeyPair
    properties:
      keyPairName: key_pair_name
  # Using name prefix to build key pair
  prefix:
    type: alicloud:ecs:EcsKeyPair
    properties:
      keyNamePrefix: terraform-test-key-pair-prefix
  # Import an existing public key to build a alicloud key pair
  publickey:
    type: alicloud:ecs:EcsKeyPair
    properties:
      keyPairName: my_public_key
      publicKey: ssh-rsa AAAAB3Nza12345678qwertyuudsfsg
Copy

Create EcsKeyPair Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new EcsKeyPair(name: string, args?: EcsKeyPairArgs, opts?: CustomResourceOptions);
@overload
def EcsKeyPair(resource_name: str,
               args: Optional[EcsKeyPairArgs] = None,
               opts: Optional[ResourceOptions] = None)

@overload
def EcsKeyPair(resource_name: str,
               opts: Optional[ResourceOptions] = None,
               key_file: Optional[str] = None,
               key_name: Optional[str] = None,
               key_name_prefix: Optional[str] = None,
               key_pair_name: Optional[str] = None,
               public_key: Optional[str] = None,
               resource_group_id: Optional[str] = None,
               tags: Optional[Mapping[str, str]] = None)
func NewEcsKeyPair(ctx *Context, name string, args *EcsKeyPairArgs, opts ...ResourceOption) (*EcsKeyPair, error)
public EcsKeyPair(string name, EcsKeyPairArgs? args = null, CustomResourceOptions? opts = null)
public EcsKeyPair(String name, EcsKeyPairArgs args)
public EcsKeyPair(String name, EcsKeyPairArgs args, CustomResourceOptions options)
type: alicloud:ecs:EcsKeyPair
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args EcsKeyPairArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args EcsKeyPairArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args EcsKeyPairArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args EcsKeyPairArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. EcsKeyPairArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var ecsKeyPairResource = new AliCloud.Ecs.EcsKeyPair("ecsKeyPairResource", new()
{
    KeyFile = "string",
    KeyNamePrefix = "string",
    KeyPairName = "string",
    PublicKey = "string",
    ResourceGroupId = "string",
    Tags = 
    {
        { "string", "string" },
    },
});
Copy
example, err := ecs.NewEcsKeyPair(ctx, "ecsKeyPairResource", &ecs.EcsKeyPairArgs{
	KeyFile:         pulumi.String("string"),
	KeyNamePrefix:   pulumi.String("string"),
	KeyPairName:     pulumi.String("string"),
	PublicKey:       pulumi.String("string"),
	ResourceGroupId: pulumi.String("string"),
	Tags: pulumi.StringMap{
		"string": pulumi.String("string"),
	},
})
Copy
var ecsKeyPairResource = new EcsKeyPair("ecsKeyPairResource", EcsKeyPairArgs.builder()
    .keyFile("string")
    .keyNamePrefix("string")
    .keyPairName("string")
    .publicKey("string")
    .resourceGroupId("string")
    .tags(Map.of("string", "string"))
    .build());
Copy
ecs_key_pair_resource = alicloud.ecs.EcsKeyPair("ecsKeyPairResource",
    key_file="string",
    key_name_prefix="string",
    key_pair_name="string",
    public_key="string",
    resource_group_id="string",
    tags={
        "string": "string",
    })
Copy
const ecsKeyPairResource = new alicloud.ecs.EcsKeyPair("ecsKeyPairResource", {
    keyFile: "string",
    keyNamePrefix: "string",
    keyPairName: "string",
    publicKey: "string",
    resourceGroupId: "string",
    tags: {
        string: "string",
    },
});
Copy
type: alicloud:ecs:EcsKeyPair
properties:
    keyFile: string
    keyNamePrefix: string
    keyPairName: string
    publicKey: string
    resourceGroupId: string
    tags:
        string: string
Copy

EcsKeyPair Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The EcsKeyPair resource accepts the following input properties:

KeyFile Changes to this property will trigger replacement. string
The key file.
KeyName Changes to this property will trigger replacement. string

Deprecated: Field key_name has been deprecated from provider version 1.121.0. New field key_pair_name instead.

KeyNamePrefix Changes to this property will trigger replacement. string
KeyPairName Changes to this property will trigger replacement. string
The name of the key pair. The name must be 2 to 128 characters in length. The name must start with a letter and cannot start with http:// or https://. The name can contain letters, digits, colons (:), underscores (_), and hyphens (-).
PublicKey string
The public key of the key pair.
ResourceGroupId string
The ID of the resource group to which to add the key pair.
Tags Dictionary<string, string>
A mapping of tags to assign to the resource.
KeyFile Changes to this property will trigger replacement. string
The key file.
KeyName Changes to this property will trigger replacement. string

Deprecated: Field key_name has been deprecated from provider version 1.121.0. New field key_pair_name instead.

KeyNamePrefix Changes to this property will trigger replacement. string
KeyPairName Changes to this property will trigger replacement. string
The name of the key pair. The name must be 2 to 128 characters in length. The name must start with a letter and cannot start with http:// or https://. The name can contain letters, digits, colons (:), underscores (_), and hyphens (-).
PublicKey string
The public key of the key pair.
ResourceGroupId string
The ID of the resource group to which to add the key pair.
Tags map[string]string
A mapping of tags to assign to the resource.
keyFile Changes to this property will trigger replacement. String
The key file.
keyName Changes to this property will trigger replacement. String

Deprecated: Field key_name has been deprecated from provider version 1.121.0. New field key_pair_name instead.

keyNamePrefix Changes to this property will trigger replacement. String
keyPairName Changes to this property will trigger replacement. String
The name of the key pair. The name must be 2 to 128 characters in length. The name must start with a letter and cannot start with http:// or https://. The name can contain letters, digits, colons (:), underscores (_), and hyphens (-).
publicKey String
The public key of the key pair.
resourceGroupId String
The ID of the resource group to which to add the key pair.
tags Map<String,String>
A mapping of tags to assign to the resource.
keyFile Changes to this property will trigger replacement. string
The key file.
keyName Changes to this property will trigger replacement. string

Deprecated: Field key_name has been deprecated from provider version 1.121.0. New field key_pair_name instead.

keyNamePrefix Changes to this property will trigger replacement. string
keyPairName Changes to this property will trigger replacement. string
The name of the key pair. The name must be 2 to 128 characters in length. The name must start with a letter and cannot start with http:// or https://. The name can contain letters, digits, colons (:), underscores (_), and hyphens (-).
publicKey string
The public key of the key pair.
resourceGroupId string
The ID of the resource group to which to add the key pair.
tags {[key: string]: string}
A mapping of tags to assign to the resource.
key_file Changes to this property will trigger replacement. str
The key file.
key_name Changes to this property will trigger replacement. str

Deprecated: Field key_name has been deprecated from provider version 1.121.0. New field key_pair_name instead.

key_name_prefix Changes to this property will trigger replacement. str
key_pair_name Changes to this property will trigger replacement. str
The name of the key pair. The name must be 2 to 128 characters in length. The name must start with a letter and cannot start with http:// or https://. The name can contain letters, digits, colons (:), underscores (_), and hyphens (-).
public_key str
The public key of the key pair.
resource_group_id str
The ID of the resource group to which to add the key pair.
tags Mapping[str, str]
A mapping of tags to assign to the resource.
keyFile Changes to this property will trigger replacement. String
The key file.
keyName Changes to this property will trigger replacement. String

Deprecated: Field key_name has been deprecated from provider version 1.121.0. New field key_pair_name instead.

keyNamePrefix Changes to this property will trigger replacement. String
keyPairName Changes to this property will trigger replacement. String
The name of the key pair. The name must be 2 to 128 characters in length. The name must start with a letter and cannot start with http:// or https://. The name can contain letters, digits, colons (:), underscores (_), and hyphens (-).
publicKey String
The public key of the key pair.
resourceGroupId String
The ID of the resource group to which to add the key pair.
tags Map<String>
A mapping of tags to assign to the resource.

Outputs

All input properties are implicitly available as output properties. Additionally, the EcsKeyPair resource produces the following output properties:

CreateTime string
(Available since v1.237.0) The time when the key pair was created.
FingerPrint string
The fingerprint of the key pair.
Id string
The provider-assigned unique ID for this managed resource.
CreateTime string
(Available since v1.237.0) The time when the key pair was created.
FingerPrint string
The fingerprint of the key pair.
Id string
The provider-assigned unique ID for this managed resource.
createTime String
(Available since v1.237.0) The time when the key pair was created.
fingerPrint String
The fingerprint of the key pair.
id String
The provider-assigned unique ID for this managed resource.
createTime string
(Available since v1.237.0) The time when the key pair was created.
fingerPrint string
The fingerprint of the key pair.
id string
The provider-assigned unique ID for this managed resource.
create_time str
(Available since v1.237.0) The time when the key pair was created.
finger_print str
The fingerprint of the key pair.
id str
The provider-assigned unique ID for this managed resource.
createTime String
(Available since v1.237.0) The time when the key pair was created.
fingerPrint String
The fingerprint of the key pair.
id String
The provider-assigned unique ID for this managed resource.

Look up Existing EcsKeyPair Resource

Get an existing EcsKeyPair resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: EcsKeyPairState, opts?: CustomResourceOptions): EcsKeyPair
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        create_time: Optional[str] = None,
        finger_print: Optional[str] = None,
        key_file: Optional[str] = None,
        key_name: Optional[str] = None,
        key_name_prefix: Optional[str] = None,
        key_pair_name: Optional[str] = None,
        public_key: Optional[str] = None,
        resource_group_id: Optional[str] = None,
        tags: Optional[Mapping[str, str]] = None) -> EcsKeyPair
func GetEcsKeyPair(ctx *Context, name string, id IDInput, state *EcsKeyPairState, opts ...ResourceOption) (*EcsKeyPair, error)
public static EcsKeyPair Get(string name, Input<string> id, EcsKeyPairState? state, CustomResourceOptions? opts = null)
public static EcsKeyPair get(String name, Output<String> id, EcsKeyPairState state, CustomResourceOptions options)
resources:  _:    type: alicloud:ecs:EcsKeyPair    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
CreateTime string
(Available since v1.237.0) The time when the key pair was created.
FingerPrint string
The fingerprint of the key pair.
KeyFile Changes to this property will trigger replacement. string
The key file.
KeyName Changes to this property will trigger replacement. string

Deprecated: Field key_name has been deprecated from provider version 1.121.0. New field key_pair_name instead.

KeyNamePrefix Changes to this property will trigger replacement. string
KeyPairName Changes to this property will trigger replacement. string
The name of the key pair. The name must be 2 to 128 characters in length. The name must start with a letter and cannot start with http:// or https://. The name can contain letters, digits, colons (:), underscores (_), and hyphens (-).
PublicKey string
The public key of the key pair.
ResourceGroupId string
The ID of the resource group to which to add the key pair.
Tags Dictionary<string, string>
A mapping of tags to assign to the resource.
CreateTime string
(Available since v1.237.0) The time when the key pair was created.
FingerPrint string
The fingerprint of the key pair.
KeyFile Changes to this property will trigger replacement. string
The key file.
KeyName Changes to this property will trigger replacement. string

Deprecated: Field key_name has been deprecated from provider version 1.121.0. New field key_pair_name instead.

KeyNamePrefix Changes to this property will trigger replacement. string
KeyPairName Changes to this property will trigger replacement. string
The name of the key pair. The name must be 2 to 128 characters in length. The name must start with a letter and cannot start with http:// or https://. The name can contain letters, digits, colons (:), underscores (_), and hyphens (-).
PublicKey string
The public key of the key pair.
ResourceGroupId string
The ID of the resource group to which to add the key pair.
Tags map[string]string
A mapping of tags to assign to the resource.
createTime String
(Available since v1.237.0) The time when the key pair was created.
fingerPrint String
The fingerprint of the key pair.
keyFile Changes to this property will trigger replacement. String
The key file.
keyName Changes to this property will trigger replacement. String

Deprecated: Field key_name has been deprecated from provider version 1.121.0. New field key_pair_name instead.

keyNamePrefix Changes to this property will trigger replacement. String
keyPairName Changes to this property will trigger replacement. String
The name of the key pair. The name must be 2 to 128 characters in length. The name must start with a letter and cannot start with http:// or https://. The name can contain letters, digits, colons (:), underscores (_), and hyphens (-).
publicKey String
The public key of the key pair.
resourceGroupId String
The ID of the resource group to which to add the key pair.
tags Map<String,String>
A mapping of tags to assign to the resource.
createTime string
(Available since v1.237.0) The time when the key pair was created.
fingerPrint string
The fingerprint of the key pair.
keyFile Changes to this property will trigger replacement. string
The key file.
keyName Changes to this property will trigger replacement. string

Deprecated: Field key_name has been deprecated from provider version 1.121.0. New field key_pair_name instead.

keyNamePrefix Changes to this property will trigger replacement. string
keyPairName Changes to this property will trigger replacement. string
The name of the key pair. The name must be 2 to 128 characters in length. The name must start with a letter and cannot start with http:// or https://. The name can contain letters, digits, colons (:), underscores (_), and hyphens (-).
publicKey string
The public key of the key pair.
resourceGroupId string
The ID of the resource group to which to add the key pair.
tags {[key: string]: string}
A mapping of tags to assign to the resource.
create_time str
(Available since v1.237.0) The time when the key pair was created.
finger_print str
The fingerprint of the key pair.
key_file Changes to this property will trigger replacement. str
The key file.
key_name Changes to this property will trigger replacement. str

Deprecated: Field key_name has been deprecated from provider version 1.121.0. New field key_pair_name instead.

key_name_prefix Changes to this property will trigger replacement. str
key_pair_name Changes to this property will trigger replacement. str
The name of the key pair. The name must be 2 to 128 characters in length. The name must start with a letter and cannot start with http:// or https://. The name can contain letters, digits, colons (:), underscores (_), and hyphens (-).
public_key str
The public key of the key pair.
resource_group_id str
The ID of the resource group to which to add the key pair.
tags Mapping[str, str]
A mapping of tags to assign to the resource.
createTime String
(Available since v1.237.0) The time when the key pair was created.
fingerPrint String
The fingerprint of the key pair.
keyFile Changes to this property will trigger replacement. String
The key file.
keyName Changes to this property will trigger replacement. String

Deprecated: Field key_name has been deprecated from provider version 1.121.0. New field key_pair_name instead.

keyNamePrefix Changes to this property will trigger replacement. String
keyPairName Changes to this property will trigger replacement. String
The name of the key pair. The name must be 2 to 128 characters in length. The name must start with a letter and cannot start with http:// or https://. The name can contain letters, digits, colons (:), underscores (_), and hyphens (-).
publicKey String
The public key of the key pair.
resourceGroupId String
The ID of the resource group to which to add the key pair.
tags Map<String>
A mapping of tags to assign to the resource.

Import

ECS Key Pair can be imported using the id, e.g.

$ pulumi import alicloud:ecs/ecsKeyPair:EcsKeyPair example <id>
Copy

To learn more about importing existing cloud resources, see Importing resources.

Package Details

Repository
Alibaba Cloud pulumi/pulumi-alicloud
License
Apache-2.0
Notes
This Pulumi package is based on the alicloud Terraform Provider.