KeyPairAttachment

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

using System.Collections.Generic;
using System.Linq;
using Pulumi;
using AliCloud = Pulumi.AliCloud;

class MyStack : Stack
{
    public MyStack()
    {
        var @default = Output.Create(AliCloud.GetZones.InvokeAsync(new AliCloud.GetZonesArgs
        {
            AvailableDiskCategory = "cloud_ssd",
            AvailableResourceCreation = "VSwitch",
        }));
        var type = @default.Apply(@default => Output.Create(AliCloud.Ecs.GetInstanceTypes.InvokeAsync(new AliCloud.Ecs.GetInstanceTypesArgs
        {
            AvailabilityZone = @default.Zones[0].Id,
            CpuCoreCount = 1,
            MemorySize = 2,
        })));
        var images = Output.Create(AliCloud.Ecs.GetImages.InvokeAsync(new AliCloud.Ecs.GetImagesArgs
        {
            MostRecent = true,
            NameRegex = "^ubuntu_18.*64",
            Owners = "system",
        }));
        var config = new Config();
        var name = config.Get("name") ?? "keyPairAttachmentName";
        var vpc = new AliCloud.Vpc.Network("vpc", new AliCloud.Vpc.NetworkArgs
        {
            CidrBlock = "10.1.0.0/21",
        });
        var vswitch = new AliCloud.Vpc.Switch("vswitch", new AliCloud.Vpc.SwitchArgs
        {
            AvailabilityZone = @default.Apply(@default => @default.Zones[0].Id),
            CidrBlock = "10.1.1.0/24",
            VpcId = vpc.Id,
        });
        var @group = new AliCloud.Ecs.SecurityGroup("group", new AliCloud.Ecs.SecurityGroupArgs
        {
            Description = "New security group",
            VpcId = vpc.Id,
        });
        var instance = new List<AliCloud.Ecs.Instance>();
        for (var rangeIndex = 0; rangeIndex < 2; rangeIndex++)
        {
            var range = new { Value = rangeIndex };
            instance.Add(new AliCloud.Ecs.Instance($"instance-{range.Value}", new AliCloud.Ecs.InstanceArgs
            {
                ImageId = images.Apply(images => images.Images[0].Id),
                InstanceChargeType = "PostPaid",
                InstanceName = $"{name}-{range.Value + 1}",
                InstanceType = type.Apply(type => type.InstanceTypes[0].Id),
                InternetChargeType = "PayByTraffic",
                InternetMaxBandwidthOut = 5,
                Password = "Test12345",
                SecurityGroups = 
                {
                    @group.Id,
                },
                SystemDiskCategory = "cloud_ssd",
                VswitchId = vswitch.Id,
            }));
        }
        var pair = new AliCloud.Ecs.KeyPair("pair", new AliCloud.Ecs.KeyPairArgs
        {
            KeyName = name,
        });
        var attachment = new AliCloud.Ecs.KeyPairAttachment("attachment", new AliCloud.Ecs.KeyPairAttachmentArgs
        {
            InstanceIds = instance.Select(__item => __item.Id).ToList(),
            KeyName = pair.Id,
        });
    }

}

Coming soon!

import pulumi
import pulumi_alicloud as alicloud

default = alicloud.get_zones(available_disk_category="cloud_ssd",
    available_resource_creation="VSwitch")
type = alicloud.ecs.get_instance_types(availability_zone=default.zones[0]["id"],
    cpu_core_count=1,
    memory_size=2)
images = alicloud.ecs.get_images(most_recent=True,
    name_regex="^ubuntu_18.*64",
    owners="system")
config = pulumi.Config()
name = config.get("name")
if name is None:
    name = "keyPairAttachmentName"
vpc = alicloud.vpc.Network("vpc", cidr_block="10.1.0.0/21")
vswitch = alicloud.vpc.Switch("vswitch",
    availability_zone=default.zones[0]["id"],
    cidr_block="10.1.1.0/24",
    vpc_id=vpc.id)
group = alicloud.ecs.SecurityGroup("group",
    description="New security group",
    vpc_id=vpc.id)
instance = []
for range in [{"value": i} for i in range(0, 2)]:
    instance.append(alicloud.ecs.Instance(f"instance-{range['value']}",
        image_id=images.images[0]["id"],
        instance_charge_type="PostPaid",
        instance_name=f"{name}-{range['value'] + 1}",
        instance_type=type.instance_types[0]["id"],
        internet_charge_type="PayByTraffic",
        internet_max_bandwidth_out=5,
        password="Test12345",
        security_groups=[group.id],
        system_disk_category="cloud_ssd",
        vswitch_id=vswitch.id))
pair = alicloud.ecs.KeyPair("pair", key_name=name)
attachment = alicloud.ecs.KeyPairAttachment("attachment",
    instance_ids=[__item.id for __item in instance],
    key_name=pair.id)
import * as pulumi from "@pulumi/pulumi";
import * as alicloud from "@pulumi/alicloud";

const config = new pulumi.Config();
const name = config.get("name") || "keyPairAttachmentName";

const defaultZones = pulumi.output(alicloud.getZones({
    availableDiskCategory: "cloud_ssd",
    availableResourceCreation: "VSwitch",
}, { async: true }));
const type = defaultZones.apply(defaultZones => alicloud.ecs.getInstanceTypes({
    availabilityZone: defaultZones.zones[0].id,
    cpuCoreCount: 1,
    memorySize: 2,
}, { async: true }));
const images = pulumi.output(alicloud.ecs.getImages({
    mostRecent: true,
    nameRegex: "^ubuntu_18.*64",
    owners: "system",
}, { async: true }));
const vpc = new alicloud.vpc.Network("vpc", {
    cidrBlock: "10.1.0.0/21",
});
const vswitch = new alicloud.vpc.Switch("vswitch", {
    availabilityZone: defaultZones.zones[0].id,
    cidrBlock: "10.1.1.0/24",
    vpcId: vpc.id,
});
const group = new alicloud.ecs.SecurityGroup("group", {
    description: "New security group",
    vpcId: vpc.id,
});
const instance: alicloud.ecs.Instance[] = [];
for (let i = 0; i < 2; i++) {
    instance.push(new alicloud.ecs.Instance(`instance-${i}`, {
        imageId: images.images[0].id,
        instanceChargeType: "PostPaid",
        instanceName: `${name}-${(i + 1)}`,
        instanceType: type.instanceTypes[0].id,
        internetChargeType: "PayByTraffic",
        internetMaxBandwidthOut: 5,
        password: "Test12345",
        securityGroups: [group.id],
        systemDiskCategory: "cloud_ssd",
        vswitchId: vswitch.id,
    }));
}
const pair = new alicloud.ecs.KeyPair("pair", {
    keyName: name,
});
const attachment = new alicloud.ecs.KeyPairAttachment("attachment", {
    instanceIds: instance.map(v => v.id),
    keyName: pair.id,
});

Create a KeyPairAttachment Resource

def KeyPairAttachment(resource_name, opts=None, force=None, instance_ids=None, key_name=None, __props__=None);
name string
The unique name of the resource.
args KeyPairAttachmentArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
opts ResourceOptions
A bag of options that control this resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args KeyPairAttachmentArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args KeyPairAttachmentArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

KeyPairAttachment Resource Properties

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

Inputs

The KeyPairAttachment resource accepts the following input properties:

InstanceIds List<string>

The list of ECS instance’s IDs.

KeyName string

The name of key pair used to bind.

Force bool

Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.

InstanceIds []string

The list of ECS instance’s IDs.

KeyName string

The name of key pair used to bind.

Force bool

Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.

instanceIds string[]

The list of ECS instance’s IDs.

keyName string

The name of key pair used to bind.

force boolean

Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.

instance_ids List[str]

The list of ECS instance’s IDs.

key_name str

The name of key pair used to bind.

force bool

Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.

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 str
The provider-assigned unique ID for this managed resource.

Look up an 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
static get(resource_name, id, opts=None, force=None, instance_ids=None, key_name=None, __props__=None);
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)
name
The unique name of the resulting resource.
id
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
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
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
The unique name of the resulting resource.
id
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 bool

Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.

InstanceIds List<string>

The list of ECS instance’s IDs.

KeyName string

The name of key pair used to bind.

Force bool

Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.

InstanceIds []string

The list of ECS instance’s IDs.

KeyName string

The name of key pair used to bind.

force boolean

Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.

instanceIds string[]

The list of ECS instance’s IDs.

keyName string

The name of key pair used to bind.

force bool

Set it to true and it will reboot instances which attached with the key pair to make key pair affect immediately.

instance_ids List[str]

The list of ECS instance’s IDs.

key_name str

The name of key pair used to bind.

Package Details

Repository
https://github.com/pulumi/pulumi-alicloud
License
Apache-2.0
Notes
This Pulumi package is based on the alicloud Terraform Provider.