Attachment
Attaches several ECS instances to a specified scaling group or remove them from it.
NOTE: ECS instances can be attached or remove only when the scaling group is active and it has no scaling activity in progress.
NOTE: There are two types ECS instances in a scaling group: “AutoCreated” and “Attached”. The total number of them can not larger than the scaling group “MaxSize”.
Example Usage
using System.Collections.Generic;
using Pulumi;
using AliCloud = Pulumi.AliCloud;
class MyStack : Stack
{
public MyStack()
{
var config = new Config();
var name = config.Get("name") ?? "essattachmentconfig";
var defaultZones = Output.Create(AliCloud.GetZones.InvokeAsync(new AliCloud.GetZonesArgs
{
AvailableDiskCategory = "cloud_efficiency",
AvailableResourceCreation = "VSwitch",
}));
var defaultInstanceTypes = defaultZones.Apply(defaultZones => Output.Create(AliCloud.Ecs.GetInstanceTypes.InvokeAsync(new AliCloud.Ecs.GetInstanceTypesArgs
{
AvailabilityZone = defaultZones.Zones[0].Id,
CpuCoreCount = 2,
MemorySize = 4,
})));
var defaultImages = Output.Create(AliCloud.Ecs.GetImages.InvokeAsync(new AliCloud.Ecs.GetImagesArgs
{
MostRecent = true,
NameRegex = "^ubuntu_18.*64",
Owners = "system",
}));
var defaultNetwork = new AliCloud.Vpc.Network("defaultNetwork", new AliCloud.Vpc.NetworkArgs
{
CidrBlock = "172.16.0.0/16",
});
var defaultSwitch = new AliCloud.Vpc.Switch("defaultSwitch", new AliCloud.Vpc.SwitchArgs
{
AvailabilityZone = defaultZones.Apply(defaultZones => defaultZones.Zones[0].Id),
CidrBlock = "172.16.0.0/24",
VpcId = defaultNetwork.Id,
});
var defaultSecurityGroup = new AliCloud.Ecs.SecurityGroup("defaultSecurityGroup", new AliCloud.Ecs.SecurityGroupArgs
{
VpcId = defaultNetwork.Id,
});
var defaultSecurityGroupRule = new AliCloud.Ecs.SecurityGroupRule("defaultSecurityGroupRule", new AliCloud.Ecs.SecurityGroupRuleArgs
{
CidrIp = "172.16.0.0/24",
IpProtocol = "tcp",
NicType = "intranet",
Policy = "accept",
PortRange = "22/22",
Priority = 1,
SecurityGroupId = defaultSecurityGroup.Id,
Type = "ingress",
});
var defaultScalingGroup = new AliCloud.Ess.ScalingGroup("defaultScalingGroup", new AliCloud.Ess.ScalingGroupArgs
{
MaxSize = 2,
MinSize = 0,
RemovalPolicies =
{
"OldestInstance",
"NewestInstance",
},
ScalingGroupName = name,
VswitchIds =
{
defaultSwitch.Id,
},
});
var defaultScalingConfiguration = new AliCloud.Ess.ScalingConfiguration("defaultScalingConfiguration", new AliCloud.Ess.ScalingConfigurationArgs
{
Active = true,
Enable = true,
ForceDelete = true,
ImageId = defaultImages.Apply(defaultImages => defaultImages.Images[0].Id),
InstanceType = defaultInstanceTypes.Apply(defaultInstanceTypes => defaultInstanceTypes.InstanceTypes[0].Id),
ScalingGroupId = defaultScalingGroup.Id,
SecurityGroupId = defaultSecurityGroup.Id,
});
var defaultInstance = new List<AliCloud.Ecs.Instance>();
for (var rangeIndex = 0; rangeIndex < 2; rangeIndex++)
{
var range = new { Value = rangeIndex };
defaultInstance.Add(new AliCloud.Ecs.Instance($"defaultInstance-{range.Value}", new AliCloud.Ecs.InstanceArgs
{
ImageId = defaultImages.Apply(defaultImages => defaultImages.Images[0].Id),
InstanceChargeType = "PostPaid",
InstanceName = name,
InstanceType = defaultInstanceTypes.Apply(defaultInstanceTypes => defaultInstanceTypes.InstanceTypes[0].Id),
InternetChargeType = "PayByTraffic",
InternetMaxBandwidthOut = 10,
SecurityGroups =
{
defaultSecurityGroup.Id,
},
SystemDiskCategory = "cloud_efficiency",
VswitchId = defaultSwitch.Id,
}));
}
var defaultAttachment = new AliCloud.Ess.Attachment("defaultAttachment", new AliCloud.Ess.AttachmentArgs
{
Force = true,
InstanceIds =
{
defaultInstance[0].Id,
defaultInstance[1].Id,
},
ScalingGroupId = defaultScalingGroup.Id,
});
}
}
Coming soon!
import pulumi
import pulumi_alicloud as alicloud
config = pulumi.Config()
name = config.get("name")
if name is None:
name = "essattachmentconfig"
default_zones = alicloud.get_zones(available_disk_category="cloud_efficiency",
available_resource_creation="VSwitch")
default_instance_types = alicloud.ecs.get_instance_types(availability_zone=default_zones.zones[0]["id"],
cpu_core_count=2,
memory_size=4)
default_images = alicloud.ecs.get_images(most_recent=True,
name_regex="^ubuntu_18.*64",
owners="system")
default_network = alicloud.vpc.Network("defaultNetwork", cidr_block="172.16.0.0/16")
default_switch = alicloud.vpc.Switch("defaultSwitch",
availability_zone=default_zones.zones[0]["id"],
cidr_block="172.16.0.0/24",
vpc_id=default_network.id)
default_security_group = alicloud.ecs.SecurityGroup("defaultSecurityGroup", vpc_id=default_network.id)
default_security_group_rule = alicloud.ecs.SecurityGroupRule("defaultSecurityGroupRule",
cidr_ip="172.16.0.0/24",
ip_protocol="tcp",
nic_type="intranet",
policy="accept",
port_range="22/22",
priority=1,
security_group_id=default_security_group.id,
type="ingress")
default_scaling_group = alicloud.ess.ScalingGroup("defaultScalingGroup",
max_size=2,
min_size=0,
removal_policies=[
"OldestInstance",
"NewestInstance",
],
scaling_group_name=name,
vswitch_ids=[default_switch.id])
default_scaling_configuration = alicloud.ess.ScalingConfiguration("defaultScalingConfiguration",
active=True,
enable=True,
force_delete=True,
image_id=default_images.images[0]["id"],
instance_type=default_instance_types.instance_types[0]["id"],
scaling_group_id=default_scaling_group.id,
security_group_id=default_security_group.id)
default_instance = []
for range in [{"value": i} for i in range(0, 2)]:
default_instance.append(alicloud.ecs.Instance(f"defaultInstance-{range['value']}",
image_id=default_images.images[0]["id"],
instance_charge_type="PostPaid",
instance_name=name,
instance_type=default_instance_types.instance_types[0]["id"],
internet_charge_type="PayByTraffic",
internet_max_bandwidth_out="10",
security_groups=[default_security_group.id],
system_disk_category="cloud_efficiency",
vswitch_id=default_switch.id))
default_attachment = alicloud.ess.Attachment("defaultAttachment",
force=True,
instance_ids=[
default_instance[0].id,
default_instance[1].id,
],
scaling_group_id=default_scaling_group.id)import * as pulumi from "@pulumi/pulumi";
import * as alicloud from "@pulumi/alicloud";
const config = new pulumi.Config();
const name = config.get("name") || "essattachmentconfig";
const defaultZones = pulumi.output(alicloud.getZones({
availableDiskCategory: "cloud_efficiency",
availableResourceCreation: "VSwitch",
}, { async: true }));
const defaultInstanceTypes = defaultZones.apply(defaultZones => alicloud.ecs.getInstanceTypes({
availabilityZone: defaultZones.zones[0].id,
cpuCoreCount: 2,
memorySize: 4,
}, { async: true }));
const defaultImages = pulumi.output(alicloud.ecs.getImages({
mostRecent: true,
nameRegex: "^ubuntu_18.*64",
owners: "system",
}, { async: true }));
const defaultNetwork = new alicloud.vpc.Network("default", {
cidrBlock: "172.16.0.0/16",
});
const defaultSwitch = new alicloud.vpc.Switch("default", {
availabilityZone: defaultZones.zones[0].id,
cidrBlock: "172.16.0.0/24",
vpcId: defaultNetwork.id,
});
const defaultSecurityGroup = new alicloud.ecs.SecurityGroup("default", {
vpcId: defaultNetwork.id,
});
const defaultSecurityGroupRule = new alicloud.ecs.SecurityGroupRule("default", {
cidrIp: "172.16.0.0/24",
ipProtocol: "tcp",
nicType: "intranet",
policy: "accept",
portRange: "22/22",
priority: 1,
securityGroupId: defaultSecurityGroup.id,
type: "ingress",
});
const defaultScalingGroup = new alicloud.ess.ScalingGroup("default", {
maxSize: 2,
minSize: 0,
removalPolicies: [
"OldestInstance",
"NewestInstance",
],
scalingGroupName: name,
vswitchIds: [defaultSwitch.id],
});
const defaultScalingConfiguration = new alicloud.ess.ScalingConfiguration("default", {
active: true,
enable: true,
forceDelete: true,
imageId: defaultImages.images[0].id,
instanceType: defaultInstanceTypes.instanceTypes[0].id,
scalingGroupId: defaultScalingGroup.id,
securityGroupId: defaultSecurityGroup.id,
});
const defaultInstance: alicloud.ecs.Instance[] = [];
for (let i = 0; i < 2; i++) {
defaultInstance.push(new alicloud.ecs.Instance(`default-${i}`, {
imageId: defaultImages.images[0].id,
instanceChargeType: "PostPaid",
instanceName: name,
instanceType: defaultInstanceTypes.instanceTypes[0].id,
internetChargeType: "PayByTraffic",
internetMaxBandwidthOut: 10,
securityGroups: [defaultSecurityGroup.id],
systemDiskCategory: "cloud_efficiency",
vswitchId: defaultSwitch.id,
}));
}
const defaultAttachment = new alicloud.ess.Attachment("default", {
force: true,
instanceIds: [
defaultInstance[0].id,
defaultInstance[1].id,
],
scalingGroupId: defaultScalingGroup.id,
});Create a Attachment Resource
new Attachment(name: string, args: AttachmentArgs, opts?: CustomResourceOptions);def Attachment(resource_name, opts=None, force=None, instance_ids=None, scaling_group_id=None, __props__=None);func NewAttachment(ctx *Context, name string, args AttachmentArgs, opts ...ResourceOption) (*Attachment, error)public Attachment(string name, AttachmentArgs args, CustomResourceOptions? opts = null)- name string
- The unique name of the resource.
- args AttachmentArgs
- 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 AttachmentArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args AttachmentArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
Attachment Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model docs.
Inputs
The Attachment resource accepts the following input properties:
- Instance
Ids List<string> ID of the ECS instance to be attached to the scaling group. You can input up to 20 IDs.
- Scaling
Group stringId ID of the scaling group of a scaling configuration.
- Force bool
Whether to remove forcibly “AutoCreated” ECS instances in order to release scaling group capacity “MaxSize” for attaching ECS instances. Default to false.
- Instance
Ids []string ID of the ECS instance to be attached to the scaling group. You can input up to 20 IDs.
- Scaling
Group stringId ID of the scaling group of a scaling configuration.
- Force bool
Whether to remove forcibly “AutoCreated” ECS instances in order to release scaling group capacity “MaxSize” for attaching ECS instances. Default to false.
- instance
Ids string[] ID of the ECS instance to be attached to the scaling group. You can input up to 20 IDs.
- scaling
Group stringId ID of the scaling group of a scaling configuration.
- force boolean
Whether to remove forcibly “AutoCreated” ECS instances in order to release scaling group capacity “MaxSize” for attaching ECS instances. Default to false.
- instance_
ids List[str] ID of the ECS instance to be attached to the scaling group. You can input up to 20 IDs.
- scaling_
group_ strid ID of the scaling group of a scaling configuration.
- force bool
Whether to remove forcibly “AutoCreated” ECS instances in order to release scaling group capacity “MaxSize” for attaching ECS instances. Default to false.
Outputs
All input properties are implicitly available as output properties. Additionally, the Attachment resource produces the following output properties:
Look up an Existing Attachment Resource
Get an existing Attachment 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?: AttachmentState, opts?: CustomResourceOptions): Attachmentstatic get(resource_name, id, opts=None, force=None, instance_ids=None, scaling_group_id=None, __props__=None);func GetAttachment(ctx *Context, name string, id IDInput, state *AttachmentState, opts ...ResourceOption) (*Attachment, error)public static Attachment Get(string name, Input<string> id, AttachmentState? 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
Whether to remove forcibly “AutoCreated” ECS instances in order to release scaling group capacity “MaxSize” for attaching ECS instances. Default to false.
- Instance
Ids List<string> ID of the ECS instance to be attached to the scaling group. You can input up to 20 IDs.
- Scaling
Group stringId ID of the scaling group of a scaling configuration.
- Force bool
Whether to remove forcibly “AutoCreated” ECS instances in order to release scaling group capacity “MaxSize” for attaching ECS instances. Default to false.
- Instance
Ids []string ID of the ECS instance to be attached to the scaling group. You can input up to 20 IDs.
- Scaling
Group stringId ID of the scaling group of a scaling configuration.
- force boolean
Whether to remove forcibly “AutoCreated” ECS instances in order to release scaling group capacity “MaxSize” for attaching ECS instances. Default to false.
- instance
Ids string[] ID of the ECS instance to be attached to the scaling group. You can input up to 20 IDs.
- scaling
Group stringId ID of the scaling group of a scaling configuration.
- force bool
Whether to remove forcibly “AutoCreated” ECS instances in order to release scaling group capacity “MaxSize” for attaching ECS instances. Default to false.
- instance_
ids List[str] ID of the ECS instance to be attached to the scaling group. You can input up to 20 IDs.
- scaling_
group_ strid ID of the scaling group of a scaling configuration.
Package Details
- Repository
- https://github.com/pulumi/pulumi-alicloud
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
alicloudTerraform Provider.