Skip to content

Instantly share code, notes, and snippets.

@shinvdu
Last active March 6, 2023 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinvdu/9307cae34727bedbe63fc4186ef6ca84 to your computer and use it in GitHub Desktop.
Save shinvdu/9307cae34727bedbe63fc4186ef6ca84 to your computer and use it in GitHub Desktop.
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.",
resourceGroupId: exampleRg.id,
cidrBlock: "172.17.0.0/16",
});
const exampleSwitch = new alicloud.vpc.Switch("exampleSwitch", {
cidrBlock: "172.17.1.0/24",
vpcId: exampleVpc.id,
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",
vpcId: exampleVpc.id,
});
const exampleSgRule = new alicloud.ecs.SecurityGroupRule("pulumiExampleSgRule", {
description: "System created security group rules.",
ipProtocol: "all",
securityGroupId: exampleSg.id,
type: "ingress",
cidrIp: "0.0.0.0/0",
});
// 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",
resourceGroupId: exampleRg.id,
securityGroups: [exampleSg.id],
spotStrategy: "NoSpot",
status: "Running",
stoppedMode: "StopCharging",
systemDiskCategory: "cloud_essd",
systemDiskPerformanceLevel: "PL0",
tags: {
company: "pulumi",
},
volumeTags: {
company: "pulumi",
},
vswitchId: exampleSwitch.id,
});
/*
hostName: Host name of the ECS, which is a string of at least two characters. “hostname” cannot start or end with “.” or “-“.
autoReleaseTime:
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.
instanceChargeType:
Valid values are PrePaid, PostPaid, The default is PostPaid.
internetChargeType:
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".
internetMaxBandwidthOut:
Maximum outgoing bandwidth to the public network, measured in Mbps (Mega bit per second). Value range: [0, 100]. Default to 0 Mbps.
keyName:
The name of key pair that can login ECS instance successfully without password. If it is specified, the password would be invalid.
password:
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.
availabilityZone:
The Zone to start the instance in. It is ignored and will be computed when set vswitch_id.
dataDisks:
InstanceDataDiskArgs[]
The list of data disks created with instance.
creditSpecification:
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.
spotStrategy:
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
status:
The instance status. Valid values: ["Running", "Stopped"]. You can control the instance start and stop through this parameter. Default to Running.
stoppedMode:
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.
systemDiskCategory:
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+.
systemDiskPerformanceLevel:
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.
systemDiskSize:
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}.
Outputs:
- 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