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

alicloud.ecs.KeyPairAttachment

Explore with Pulumi AI

DEPRECATED: This resource has been renamed to alicloud.ecs.EcsKeyPairAttachment from version 1.121.0.

Provides a key pair attachment resource to bind key pair for several ECS instances.

NOTE: After the key pair is attached with sone instances, there instances must be rebooted to make the key pair affect.

Example Usage

Basic Usage

Coming soon!
Coming soon!
Coming soon!
Coming soon!
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.alicloud.AlicloudFunctions;
import com.pulumi.alicloud.inputs.GetZonesArgs;
import com.pulumi.alicloud.ecs.EcsFunctions;
import com.pulumi.alicloud.ecs.inputs.GetInstanceTypesArgs;
import com.pulumi.alicloud.ecs.inputs.GetImagesArgs;
import com.pulumi.alicloud.vpc.Network;
import com.pulumi.alicloud.vpc.NetworkArgs;
import com.pulumi.alicloud.vpc.Switch;
import com.pulumi.alicloud.vpc.SwitchArgs;
import com.pulumi.alicloud.ecs.SecurityGroup;
import com.pulumi.alicloud.ecs.SecurityGroupArgs;
import com.pulumi.alicloud.ecs.Instance;
import com.pulumi.alicloud.ecs.InstanceArgs;
import com.pulumi.alicloud.ecs.KeyPair;
import com.pulumi.alicloud.ecs.KeyPairArgs;
import com.pulumi.alicloud.ecs.KeyPairAttachment;
import com.pulumi.alicloud.ecs.KeyPairAttachmentArgs;
import com.pulumi.codegen.internal.KeyedValue;
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 config = ctx.config();
        final var default = AlicloudFunctions.getZones(GetZonesArgs.builder()
            .availableDiskCategory("cloud_ssd")
            .availableResourceCreation("VSwitch")
            .build());

        final var type = EcsFunctions.getInstanceTypes(GetInstanceTypesArgs.builder()
            .avaiabilityZone(default_.zones()[0].id())
            .cpuCoreCount(1)
            .memorySize(2)
            .build());

        final var images = EcsFunctions.getImages(GetImagesArgs.builder()
            .nameRegex("^ubuntu_18.*64")
            .mostRecent(true)
            .owners("system")
            .build());

        final var name = config.get("name").orElse("keyPairAttachmentName");
        var vpc = new Network("vpc", NetworkArgs.builder()
            .vpcName(name)
            .cidrBlock("10.1.0.0/21")
            .build());

        var vswitch = new Switch("vswitch", SwitchArgs.builder()
            .vpcId(vpc.id())
            .cidrBlock("10.1.1.0/24")
            .zoneId(default_.zones()[0].id())
            .vswitchName(name)
            .build());

        var group = new SecurityGroup("group", SecurityGroupArgs.builder()
            .name(name)
            .description("New security group")
            .vpcId(vpc.id())
            .build());

        for (var i = 0; i < 2; i++) {
            new Instance("instance-" + i, InstanceArgs.builder()
                .instanceName(String.format("%s-%s", name,range.value() + 1))
                .imageId(images.applyValue(getImagesResult -> getImagesResult.images()[0].id()))
                .instanceType(type.applyValue(getInstanceTypesResult -> getInstanceTypesResult.instanceTypes()[0].id()))
                .securityGroups(group.id())
                .vswitchId(vswitch.id())
                .internetChargeType("PayByTraffic")
                .internetMaxBandwidthOut(5)
                .password("Test12345")
                .instanceChargeType("PostPaid")
                .systemDiskCategory("cloud_ssd")
                .build());

        
}
        var pair = new KeyPair("pair", KeyPairArgs.builder()
            .keyName(name)
            .build());

        var attachment = new KeyPairAttachment("attachment", KeyPairAttachmentArgs.builder()
            .keyName(pair.id())
            .instanceIds(instance.stream().map(element -> element.id()).collect(toList()))
            .build());

    }
}
Copy
Coming soon!

Create KeyPairAttachment Resource

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

Constructor syntax

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

@overload
def KeyPairAttachment(resource_name: str,
                      opts: Optional[ResourceOptions] = None,
                      instance_ids: Optional[Sequence[str]] = None,
                      force: Optional[bool] = None,
                      key_name: Optional[str] = None,
                      key_pair_name: Optional[str] = None)
func NewKeyPairAttachment(ctx *Context, name string, args KeyPairAttachmentArgs, opts ...ResourceOption) (*KeyPairAttachment, error)
public KeyPairAttachment(string name, KeyPairAttachmentArgs args, CustomResourceOptions? opts = null)
public KeyPairAttachment(String name, KeyPairAttachmentArgs args)
public KeyPairAttachment(String name, KeyPairAttachmentArgs args, CustomResourceOptions options)
type: alicloud:ecs:KeyPairAttachment
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 This property is required. KeyPairAttachmentArgs
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 This property is required. KeyPairAttachmentArgs
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 This property is required. KeyPairAttachmentArgs
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 This property is required. KeyPairAttachmentArgs
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. KeyPairAttachmentArgs
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 keyPairAttachmentResource = new AliCloud.Ecs.KeyPairAttachment("keyPairAttachmentResource", new()
{
    InstanceIds = new[]
    {
        "string",
    },
    Force = false,
    KeyPairName = "string",
});
Copy
example, err := ecs.NewKeyPairAttachment(ctx, "keyPairAttachmentResource", &ecs.KeyPairAttachmentArgs{
	InstanceIds: pulumi.StringArray{
		pulumi.String("string"),
	},
	Force:       pulumi.Bool(false),
	KeyPairName: pulumi.String("string"),
})
Copy
var keyPairAttachmentResource = new KeyPairAttachment("keyPairAttachmentResource", KeyPairAttachmentArgs.builder()
    .instanceIds("string")
    .force(false)
    .keyPairName("string")
    .build());
Copy
key_pair_attachment_resource = alicloud.ecs.KeyPairAttachment("keyPairAttachmentResource",
    instance_ids=["string"],
    force=False,
    key_pair_name="string")
Copy
const keyPairAttachmentResource = new alicloud.ecs.KeyPairAttachment("keyPairAttachmentResource", {
    instanceIds: ["string"],
    force: false,
    keyPairName: "string",
});
Copy
type: alicloud:ecs:KeyPairAttachment
properties:
    force: false
    instanceIds:
        - string
    keyPairName: string
Copy

KeyPairAttachment 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 KeyPairAttachment resource accepts the following input properties:

InstanceIds
This property is required.
Changes to this property will trigger replacement.
List<string>
The list of ECS instance's IDs.
Force Changes to this property will trigger replacement. bool
Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.
KeyName Changes to this property will trigger replacement. string
The name of key pair used to bind.

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

KeyPairName Changes to this property will trigger replacement. string
InstanceIds
This property is required.
Changes to this property will trigger replacement.
[]string
The list of ECS instance's IDs.
Force Changes to this property will trigger replacement. bool
Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.
KeyName Changes to this property will trigger replacement. string
The name of key pair used to bind.

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

KeyPairName Changes to this property will trigger replacement. string
instanceIds
This property is required.
Changes to this property will trigger replacement.
List<String>
The list of ECS instance's IDs.
force Changes to this property will trigger replacement. Boolean
Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.
keyName Changes to this property will trigger replacement. String
The name of key pair used to bind.

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

keyPairName Changes to this property will trigger replacement. String
instanceIds
This property is required.
Changes to this property will trigger replacement.
string[]
The list of ECS instance's IDs.
force Changes to this property will trigger replacement. boolean
Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.
keyName Changes to this property will trigger replacement. string
The name of key pair used to bind.

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

keyPairName Changes to this property will trigger replacement. string
instance_ids
This property is required.
Changes to this property will trigger replacement.
Sequence[str]
The list of ECS instance's IDs.
force Changes to this property will trigger replacement. bool
Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.
key_name Changes to this property will trigger replacement. str
The name of key pair used to bind.

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

key_pair_name Changes to this property will trigger replacement. str
instanceIds
This property is required.
Changes to this property will trigger replacement.
List<String>
The list of ECS instance's IDs.
force Changes to this property will trigger replacement. Boolean
Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.
keyName Changes to this property will trigger replacement. String
The name of key pair used to bind.

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

keyPairName Changes to this property will trigger replacement. String

Outputs

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

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.

Look up Existing KeyPairAttachment Resource

Get an existing KeyPairAttachment 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?: KeyPairAttachmentState, opts?: CustomResourceOptions): KeyPairAttachment
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        force: Optional[bool] = None,
        instance_ids: Optional[Sequence[str]] = None,
        key_name: Optional[str] = None,
        key_pair_name: Optional[str] = None) -> KeyPairAttachment
func GetKeyPairAttachment(ctx *Context, name string, id IDInput, state *KeyPairAttachmentState, opts ...ResourceOption) (*KeyPairAttachment, error)
public static KeyPairAttachment Get(string name, Input<string> id, KeyPairAttachmentState? state, CustomResourceOptions? opts = null)
public static KeyPairAttachment get(String name, Output<String> id, KeyPairAttachmentState state, CustomResourceOptions options)
resources:  _:    type: alicloud:ecs:KeyPairAttachment    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:
Force Changes to this property will trigger replacement. bool
Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.
InstanceIds Changes to this property will trigger replacement. List<string>
The list of ECS instance's IDs.
KeyName Changes to this property will trigger replacement. string
The name of key pair used to bind.

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

KeyPairName Changes to this property will trigger replacement. string
Force Changes to this property will trigger replacement. bool
Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.
InstanceIds Changes to this property will trigger replacement. []string
The list of ECS instance's IDs.
KeyName Changes to this property will trigger replacement. string
The name of key pair used to bind.

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

KeyPairName Changes to this property will trigger replacement. string
force Changes to this property will trigger replacement. Boolean
Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.
instanceIds Changes to this property will trigger replacement. List<String>
The list of ECS instance's IDs.
keyName Changes to this property will trigger replacement. String
The name of key pair used to bind.

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

keyPairName Changes to this property will trigger replacement. String
force Changes to this property will trigger replacement. boolean
Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.
instanceIds Changes to this property will trigger replacement. string[]
The list of ECS instance's IDs.
keyName Changes to this property will trigger replacement. string
The name of key pair used to bind.

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

keyPairName Changes to this property will trigger replacement. string
force Changes to this property will trigger replacement. bool
Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.
instance_ids Changes to this property will trigger replacement. Sequence[str]
The list of ECS instance's IDs.
key_name Changes to this property will trigger replacement. str
The name of key pair used to bind.

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

key_pair_name Changes to this property will trigger replacement. str
force Changes to this property will trigger replacement. Boolean
Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.
instanceIds Changes to this property will trigger replacement. List<String>
The list of ECS instance's IDs.
keyName Changes to this property will trigger replacement. String
The name of key pair used to bind.

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

keyPairName Changes to this property will trigger replacement. String

Package Details

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