Skip to content

Instantly share code, notes, and snippets.

Last active March 6, 2023 01:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
alicloud pulumi ecs javascript working example
"use strict";
const pulumi = require("@pulumi/pulumi");
const alicloud = require("@pulumi/alicloud");
const exampleRg = new alicloud.resourcemanager.ResourceGroup("pulumiDeployment", {
displayName: "Pulumi Example RG",
// error: [ERROR] terraform-provider-alicloud@v1.176.0/alicloud/resource_alicloud_resource_manager_resource_group.go:95:
// [ERROR] Argument "name" or "resource_group_name" must be set one!
resourceGroupName: "pulumiDeployment",
const exampleVpc = new alicloud.vpc.Network("pulumiExampleVpc", {
description: "Pulumi Example VPC.",
cidrBlock: "",
const exampleSwitch = new alicloud.vpc.Switch("exampleSwitch", {
cidrBlock: "",
vswitchName: "xxxxx",
zoneId: "cn-shanghai-l",
}, {
protect: false,
zoneId, string:
The AZ for the switch. Note: Required for a VPC switch.
const exampleSg = new alicloud.ecs.SecurityGroup("pulumiExampleSg", {
description: "System created security group.",
innerAccessPolicy: "Accept",
const exampleSgRule = new alicloud.ecs.SecurityGroupRule("pulumiExampleSgRule", {
description: "System created security group rules.",
ipProtocol: "all",
type: "ingress",
cidrIp: "",
// Import an existing public key to build a alicloud key pair
const publickey = new alicloud.ecs.EcsKeyPair("publickey", {
keyPairName: "tian_thinkpad",
publicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDN+pmQajq/WDUnbK2yvGFiiZ+CSNFYSMKcPX6k14pVGSIviQYffus4DRIXUftfwAd1EQt4xJdMrMy4eDTLhxvJ6JUbkgqu2UVjfSvTzinTc+7FOBV1VrS+CSuNcviqd0z6Kd2djuU0+zPPMFHrM+orq882fv5tewYseslwZXL6/ZzVZT0ieLEEn75KRAuk1eixT4ODq8C2RfMPVdtWkeMZvEF4qeJI1SSGR7yfyf6jowbiZtGGjbyvf//8CU1jIP7bUU4FrRjdkrnzA+XvaPRcvD4+DSrP2qQ066dzeQgeXGo6kDTYRCNAFH1vBvDhZZsBcaX8j silas@silas-ThinkPad",
const exampleInstance = new alicloud.ecs.Instance("pulumiExampleInstance", {
// availabilityZone: "cn-shanghai",
availabilityZone: "cn-shanghai-l",
creditSpecification: "Standard",
imageId: "aliyun_3_x64_20G_alibase_20220527.vhd",
instanceChargeType: "PostPaid",
instanceType: "ecs.t6-c2m1.large",
internetChargeType: "PayByTraffic",
internetMaxBandwidthOut: 100,
keyName: "tian_thinkpad",
securityGroups: [],
spotStrategy: "NoSpot",
status: "Running",
stoppedMode: "StopCharging",
systemDiskCategory: "cloud_essd",
systemDiskPerformanceLevel: "PL0",
tags: {
company: "pulumi",
volumeTags: {
company: "pulumi",
hostName: Host name of the ECS, which is a string of at least two characters. “hostname” cannot start or end with “.” or “-“.
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. Set it to null can cancel automatic release attribute and the ECS instance will not be released automatically.
Valid values are PrePaid, PostPaid, The default is PostPaid.
Internet charge type of the instance, Valid values are PayByBandwidth, PayByTraffic. Default is PayByTraffic. At present, 'PrePaid' instance cannot change the value to "PayByBandwidth" from "PayByTraffic".
Maximum outgoing bandwidth to the public network, measured in Mbps (Mega bit per second). Value range: [0, 100]. Default to 0 Mbps.
The name of key pair that can login ECS instance successfully without password. If it is specified, the password would be invalid.
Password to an instance is a string of 8 to 30 characters. It must contain uppercase/lowercase letters and numerals, but cannot contain special symbols. When it is changed, the instance will reboot to make the change take effect.
The Zone to start the instance in. It is ignored and will be computed when set vswitch_id.
The list of data disks created with instance.
Performance mode of the t5 burstable instance. Valid values: 'Standard', 'Unlimited'.
spotDuration, number:
The retention time of the preemptive instance in hours. Valid values: 0, 1, 2, 3, 4, 5, 6. Retention duration 2~6 is under invitation test, please submit a work order if you need to open. If the value is 0, the mode is no protection period. Default value is 1.
spotPriceLimit, number:
The hourly price threshold of a instance, and it takes effect only when parameter 'spot_strategy' is 'SpotWithPriceLimit'. Three decimals is allowed at most.
The spot strategy of a Pay-As-You-Go instance, and it takes effect only when parameter instance_charge_type is 'PostPaid'. Value range:
- NoSpot: A regular Pay-As-You-Go instance.
- SpotWithPriceLimit: A price threshold for a spot instance
- SpotAsPriceGo: A price that is based on the highest Pay-As-You-Go instance
The instance status. Valid values: ["Running", "Stopped"]. You can control the instance start and stop through this parameter. Default to Running.
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.
Valid values are ephemeral_ssd, cloud_efficiency, cloud_ssd, cloud_essd, cloud, cloud_auto. only is used to some none I/O optimized instance. Default to cloud_efficiency. Valid values cloud_auto Available in 1.184.0+.
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.
Size of the system disk, measured in GiB. Value range: [20, 500]. The specified value must be equal to or greater than max{20, Imagesize}. Default value: max{40, ImageSize}.
- id, string:
The provider-assigned unique ID for this managed resource.
- publicIp, string:
The instance public ip.
exports.publicIp = exampleInstance.publicIp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment