Instance
Provides a ECS instance resource.
NOTE: Available since v1.0.0 NOTE: From version v1.213.0, you can specify
launch_template_idandlaunch_template_versionto use a launch template. This eliminates the need to configure a large number of parameters every time you create instances.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as alicloud from "@pulumi/alicloud";
const config = new pulumi.Config();
const name = config.get("name") || "terraform-example";
// Create a new ECS instance for VPC
const vpc = new alicloud.vpc.Network("vpc", {
vpcName: name,
cidrBlock: "172.16.0.0/16",
});
// Create a new ECS instance for a VPC
const group = new alicloud.ecs.SecurityGroup("group", {
name: name,
description: "foo",
vpcId: vpc.id,
});
const key = new alicloud.kms.Key("key", {
description: "Hello KMS",
pendingWindowInDays: 7,
status: "Enabled",
});
const default = alicloud.getZones({
availableDiskCategory: "cloud_efficiency",
availableResourceCreation: "VSwitch",
});
const vswitch = new alicloud.vpc.Switch("vswitch", {
vpcId: vpc.id,
cidrBlock: "172.16.0.0/24",
zoneId: _default.then(_default => _default.zones?.[0]?.id),
vswitchName: name,
});
const instance = new alicloud.ecs.Instance("instance", {
availabilityZone: _default.then(_default => _default.zones?.[0]?.id),
securityGroups: [group].map(__item => __item.id),
instanceType: "ecs.n4.large",
systemDiskCategory: "cloud_efficiency",
systemDiskName: name,
systemDiskDescription: "test_foo_system_disk_description",
imageId: "ubuntu_18_04_64_20G_alibase_20190624.vhd",
instanceName: name,
vswitchId: vswitch.id,
internetMaxBandwidthOut: 10,
dataDisks: [{
name: "disk2",
size: 20,
category: "cloud_efficiency",
description: "disk2",
encrypted: true,
kmsKeyId: key.id,
}],
});import pulumi
import pulumi_alicloud as alicloud
config = pulumi.Config()
name = config.get("name")
if name is None:
name = "terraform-example"
# Create a new ECS instance for VPC
vpc = alicloud.vpc.Network("vpc",
vpc_name=name,
cidr_block="172.16.0.0/16")
# Create a new ECS instance for a VPC
group = alicloud.ecs.SecurityGroup("group",
name=name,
description="foo",
vpc_id=vpc.id)
key = alicloud.kms.Key("key",
description="Hello KMS",
pending_window_in_days=7,
status="Enabled")
default = alicloud.get_zones(available_disk_category="cloud_efficiency",
available_resource_creation="VSwitch")
vswitch = alicloud.vpc.Switch("vswitch",
vpc_id=vpc.id,
cidr_block="172.16.0.0/24",
zone_id=default.zones[0].id,
vswitch_name=name)
instance = alicloud.ecs.Instance("instance",
availability_zone=default.zones[0].id,
security_groups=[__item.id for __item in [group]],
instance_type="ecs.n4.large",
system_disk_category="cloud_efficiency",
system_disk_name=name,
system_disk_description="test_foo_system_disk_description",
image_id="ubuntu_18_04_64_20G_alibase_20190624.vhd",
instance_name=name,
vswitch_id=vswitch.id,
internet_max_bandwidth_out=10,
data_disks=[alicloud.ecs.InstanceDataDiskArgs(
name="disk2",
size=20,
category="cloud_efficiency",
description="disk2",
encrypted=True,
kms_key_id=key.id,
)])using System.Collections.Generic;
using System.Linq;
using Pulumi;
using AliCloud = Pulumi.AliCloud;
return await Deployment.RunAsync(() =>
{
var config = new Config();
var name = config.Get("name") ?? "terraform-example";
// Create a new ECS instance for VPC
var vpc = new AliCloud.Vpc.Network("vpc", new()
{
VpcName = name,
CidrBlock = "172.16.0.0/16",
});
// Create a new ECS instance for a VPC
var @group = new AliCloud.Ecs.SecurityGroup("group", new()
{
Name = name,
Description = "foo",
VpcId = vpc.Id,
});
var key = new AliCloud.Kms.Key("key", new()
{
Description = "Hello KMS",
PendingWindowInDays = 7,
Status = "Enabled",
});
var @default = AliCloud.GetZones.Invoke(new()
{
AvailableDiskCategory = "cloud_efficiency",
AvailableResourceCreation = "VSwitch",
});
var vswitch = new AliCloud.Vpc.Switch("vswitch", new()
{
VpcId = vpc.Id,
CidrBlock = "172.16.0.0/24",
ZoneId = @default.Apply(@default => @default.Apply(getZonesResult => getZonesResult.Zones[0]?.Id)),
VswitchName = name,
});
var instance = new AliCloud.Ecs.Instance("instance", new()
{
AvailabilityZone = @default.Apply(@default => @default.Apply(getZonesResult => getZonesResult.Zones[0]?.Id)),
SecurityGroups = new[]
{
@group,
}.Select(__item => __item.Id).ToList(),
InstanceType = "ecs.n4.large",
SystemDiskCategory = "cloud_efficiency",
SystemDiskName = name,
SystemDiskDescription = "test_foo_system_disk_description",
ImageId = "ubuntu_18_04_64_20G_alibase_20190624.vhd",
InstanceName = name,
VswitchId = vswitch.Id,
InternetMaxBandwidthOut = 10,
DataDisks = new[]
{
new AliCloud.Ecs.Inputs.InstanceDataDiskArgs
{
Name = "disk2",
Size = 20,
Category = "cloud_efficiency",
Description = "disk2",
Encrypted = true,
KmsKeyId = key.Id,
},
},
});
});package main
import (
"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud"
"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/ecs"
"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/kms"
"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/vpc"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
cfg := config.New(ctx, "")
name := "terraform-example";
if param := cfg.Get("name"); param != ""{
name = param
}
// Create a new ECS instance for VPC
vpc, err := vpc.NewNetwork(ctx, "vpc", &vpc.NetworkArgs{
VpcName: pulumi.String(name),
CidrBlock: pulumi.String("172.16.0.0/16"),
})
if err != nil {
return err
}
// Create a new ECS instance for a VPC
group, err := ecs.NewSecurityGroup(ctx, "group", &ecs.SecurityGroupArgs{
Name: pulumi.String(name),
Description: pulumi.String("foo"),
VpcId: vpc.ID(),
})
if err != nil {
return err
}
key, err := kms.NewKey(ctx, "key", &kms.KeyArgs{
Description: pulumi.String("Hello KMS"),
PendingWindowInDays: pulumi.Int(7),
Status: pulumi.String("Enabled"),
})
if err != nil {
return err
}
_default, err := alicloud.GetZones(ctx, &alicloud.GetZonesArgs{
AvailableDiskCategory: pulumi.StringRef("cloud_efficiency"),
AvailableResourceCreation: pulumi.StringRef("VSwitch"),
}, nil);
if err != nil {
return err
}
vswitch, err := vpc.NewSwitch(ctx, "vswitch", &vpc.SwitchArgs{
VpcId: vpc.ID(),
CidrBlock: pulumi.String("172.16.0.0/24"),
ZoneId: pulumi.String(_default.Zones[0].Id),
VswitchName: pulumi.String(name),
})
if err != nil {
return err
}
var splat0 pulumi.StringArray
for _, val0 := range %!v(PANIC=Format method: fatal: An assertion has failed: tok: ) {
splat0 = append(splat0, val0.ID())
}
_, err = ecs.NewInstance(ctx, "instance", &ecs.InstanceArgs{
AvailabilityZone: pulumi.String(_default.Zones[0].Id),
SecurityGroups: splat0,
InstanceType: pulumi.String("ecs.n4.large"),
SystemDiskCategory: pulumi.String("cloud_efficiency"),
SystemDiskName: pulumi.String(name),
SystemDiskDescription: pulumi.String("test_foo_system_disk_description"),
ImageId: pulumi.String("ubuntu_18_04_64_20G_alibase_20190624.vhd"),
InstanceName: pulumi.String(name),
VswitchId: vswitch.ID(),
InternetMaxBandwidthOut: pulumi.Int(10),
DataDisks: ecs.InstanceDataDiskArray{
&ecs.InstanceDataDiskArgs{
Name: pulumi.String("disk2"),
Size: pulumi.Int(20),
Category: pulumi.String("cloud_efficiency"),
Description: pulumi.String("disk2"),
Encrypted: pulumi.Bool(true),
KmsKeyId: key.ID(),
},
},
})
if err != nil {
return err
}
return nil
})
}package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.alicloud.vpc.Network;
import com.pulumi.alicloud.vpc.NetworkArgs;
import com.pulumi.alicloud.ecs.SecurityGroup;
import com.pulumi.alicloud.ecs.SecurityGroupArgs;
import com.pulumi.alicloud.kms.Key;
import com.pulumi.alicloud.kms.KeyArgs;
import com.pulumi.alicloud.AlicloudFunctions;
import com.pulumi.alicloud.inputs.GetZonesArgs;
import com.pulumi.alicloud.vpc.Switch;
import com.pulumi.alicloud.vpc.SwitchArgs;
import com.pulumi.alicloud.ecs.Instance;
import com.pulumi.alicloud.ecs.InstanceArgs;
import com.pulumi.alicloud.ecs.inputs.InstanceDataDiskArgs;
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 name = config.get("name").orElse("terraform-example");
// Create a new ECS instance for VPC
var vpc = new Network("vpc", NetworkArgs.builder()
.vpcName(name)
.cidrBlock("172.16.0.0/16")
.build());
// Create a new ECS instance for a VPC
var group = new SecurityGroup("group", SecurityGroupArgs.builder()
.name(name)
.description("foo")
.vpcId(vpc.id())
.build());
var key = new Key("key", KeyArgs.builder()
.description("Hello KMS")
.pendingWindowInDays("7")
.status("Enabled")
.build());
final var default = AlicloudFunctions.getZones(GetZonesArgs.builder()
.availableDiskCategory("cloud_efficiency")
.availableResourceCreation("VSwitch")
.build());
var vswitch = new Switch("vswitch", SwitchArgs.builder()
.vpcId(vpc.id())
.cidrBlock("172.16.0.0/24")
.zoneId(default_.zones()[0].id())
.vswitchName(name)
.build());
var instance = new Instance("instance", InstanceArgs.builder()
.availabilityZone(default_.zones()[0].id())
.securityGroups(group.stream().map(element -> element.id()).collect(toList()))
.instanceType("ecs.n4.large")
.systemDiskCategory("cloud_efficiency")
.systemDiskName(name)
.systemDiskDescription("test_foo_system_disk_description")
.imageId("ubuntu_18_04_64_20G_alibase_20190624.vhd")
.instanceName(name)
.vswitchId(vswitch.id())
.internetMaxBandwidthOut(10)
.dataDisks(InstanceDataDiskArgs.builder()
.name("disk2")
.size(20)
.category("cloud_efficiency")
.description("disk2")
.encrypted(true)
.kmsKeyId(key.id())
.build())
.build());
}
}Module Support
You can use the existing ecs-instance module to create several ECS instances one-click.
Import
Instance can be imported using the id, e.g.
$ pulumi import alicloud:ecs/instance:Instance example i-abc12345678Properties
The automatic release time of the PostPaid instance. The time follows the ISO 8601 standard and is in UTC time. Format: yyyy-MM-ddTHH:mm:ssZ. It must be at least half an hour later than the current time and less than 3 years since the current time. Setting it to null can cancel automatic release feature, and the ECS instance will not be released automatically.
Host name of the ECS, which is a string of at least two characters. “hostname” cannot start or end with “.” or “-“. In addition, two or more consecutive “.” or “-“ symbols are not allowed. On Windows, the host name can contain a maximum of 15 characters, which can be a combination of uppercase/lowercase letters, numerals, and “-“. The host name cannot contain dots (“.”) or contain only numeric characters. When it is changed, the instance will reboot to make the change take effect. On other OSs such as Linux, the host name can contain a maximum of 64 characters, which can be segments separated by dots (“.”), where each segment can contain uppercase/lowercase letters, numerals, or “_“. When it is changed, the instance will reboot to make the change take effect.
Valid values are PrePaid, PostPaid, The default is PostPaid. NOTE: Since 1.9.6, it can be changed each other between PostPaid and PrePaid. However, since some limitation about CPU core count in one month, there strongly recommends that Don't change instance_charge_type frequentlly in one month.
An KMS encryption context used to decrypt kms_encrypted_password before creating or updating an instance with kms_encrypted_password. See Encryption Context. It is valid when kms_encrypted_password is set. When it is changed, the instance will reboot to make the change take effect.
The ID of the launch template. For more information, see DescribeLaunchTemplates.To use a launch template to create an instance, you must use the launch_template_id or launch_template_name parameter to specify the launch template.
The stop mode of the pay-as-you-go instance. Valid values: StopCharging,KeepCharging, Not-applicable. Default value: If the prerequisites required for enabling the economical mode are met, and you have enabled this mode in the ECS console, the default value is StopCharging. For more information, see "Enable the economical mode" in Economical mode. Otherwise, the default value is KeepCharging. Note: Not-applicable: Economical mode is not applicable to the instance.`
The performance level of the ESSD used as the system disk, Valid values: PL0, PL1, PL2, PL3, Default to PL1;For more information about ESSD, See Encryption Context.
User-defined data to customize the startup behaviors of an ECS instance and to pass data into an ECS instance. It supports to setting a base64-encoded value, and it is the recommended usage. From version 1.60.0, it can be updated in-place. If updated, the instance will reboot to make the change take effect. Note: Not all changes will take effect, and it depends on cloud-init module type.