Alibaba Cloud
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
{
NameRegex = "^ubuntu_18.*64",
MostRecent = true,
Owners = "system",
}));
var defaultNetwork = new AliCloud.Vpc.Network("defaultNetwork", new AliCloud.Vpc.NetworkArgs
{
VpcName = name,
CidrBlock = "172.16.0.0/16",
});
var defaultSwitch = new AliCloud.Vpc.Switch("defaultSwitch", new AliCloud.Vpc.SwitchArgs
{
VpcId = defaultNetwork.Id,
CidrBlock = "172.16.0.0/24",
ZoneId = defaultZones.Apply(defaultZones => defaultZones.Zones?[0]?.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
{
Type = "ingress",
IpProtocol = "tcp",
NicType = "intranet",
Policy = "accept",
PortRange = "22/22",
Priority = 1,
SecurityGroupId = defaultSecurityGroup.Id,
CidrIp = "172.16.0.0/24",
});
var defaultScalingGroup = new AliCloud.Ess.ScalingGroup("defaultScalingGroup", new AliCloud.Ess.ScalingGroupArgs
{
MinSize = 0,
MaxSize = 2,
ScalingGroupName = name,
RemovalPolicies =
{
"OldestInstance",
"NewestInstance",
},
VswitchIds =
{
defaultSwitch.Id,
},
});
var defaultScalingConfiguration = new AliCloud.Ess.ScalingConfiguration("defaultScalingConfiguration", new AliCloud.Ess.ScalingConfigurationArgs
{
ScalingGroupId = defaultScalingGroup.Id,
ImageId = defaultImages.Apply(defaultImages => defaultImages.Images?[0]?.Id),
InstanceType = defaultInstanceTypes.Apply(defaultInstanceTypes => defaultInstanceTypes.InstanceTypes?[0]?.Id),
SecurityGroupId = defaultSecurityGroup.Id,
ForceDelete = true,
Active = true,
Enable = true,
});
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),
InstanceType = defaultInstanceTypes.Apply(defaultInstanceTypes => defaultInstanceTypes.InstanceTypes?[0]?.Id),
SecurityGroups =
{
defaultSecurityGroup.Id,
},
InternetChargeType = "PayByTraffic",
InternetMaxBandwidthOut = 10,
InstanceChargeType = "PostPaid",
SystemDiskCategory = "cloud_efficiency",
VswitchId = defaultSwitch.Id,
InstanceName = name,
}));
}
var defaultAttachment = new AliCloud.Ess.Attachment("defaultAttachment", new AliCloud.Ess.AttachmentArgs
{
ScalingGroupId = defaultScalingGroup.Id,
InstanceIds =
{
defaultInstance[0].Id,
defaultInstance[1].Id,
},
Force = true,
});
}
}
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/ess"
"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 := "essattachmentconfig"
if param := cfg.Get("name"); param != "" {
name = param
}
defaultZones, err := alicloud.GetZones(ctx, &GetZonesArgs{
AvailableDiskCategory: pulumi.StringRef("cloud_efficiency"),
AvailableResourceCreation: pulumi.StringRef("VSwitch"),
}, nil)
if err != nil {
return err
}
defaultInstanceTypes, err := ecs.GetInstanceTypes(ctx, &ecs.GetInstanceTypesArgs{
AvailabilityZone: pulumi.StringRef(defaultZones.Zones[0].Id),
CpuCoreCount: pulumi.IntRef(2),
MemorySize: pulumi.Float64Ref(4),
}, nil)
if err != nil {
return err
}
defaultImages, err := ecs.GetImages(ctx, &ecs.GetImagesArgs{
NameRegex: pulumi.StringRef("^ubuntu_18.*64"),
MostRecent: pulumi.BoolRef(true),
Owners: pulumi.StringRef("system"),
}, nil)
if err != nil {
return err
}
defaultNetwork, err := vpc.NewNetwork(ctx, "defaultNetwork", &vpc.NetworkArgs{
VpcName: pulumi.String(name),
CidrBlock: pulumi.String("172.16.0.0/16"),
})
if err != nil {
return err
}
defaultSwitch, err := vpc.NewSwitch(ctx, "defaultSwitch", &vpc.SwitchArgs{
VpcId: defaultNetwork.ID(),
CidrBlock: pulumi.String("172.16.0.0/24"),
ZoneId: pulumi.String(defaultZones.Zones[0].Id),
})
if err != nil {
return err
}
defaultSecurityGroup, err := ecs.NewSecurityGroup(ctx, "defaultSecurityGroup", &ecs.SecurityGroupArgs{
VpcId: defaultNetwork.ID(),
})
if err != nil {
return err
}
_, err = ecs.NewSecurityGroupRule(ctx, "defaultSecurityGroupRule", &ecs.SecurityGroupRuleArgs{
Type: pulumi.String("ingress"),
IpProtocol: pulumi.String("tcp"),
NicType: pulumi.String("intranet"),
Policy: pulumi.String("accept"),
PortRange: pulumi.String("22/22"),
Priority: pulumi.Int(1),
SecurityGroupId: defaultSecurityGroup.ID(),
CidrIp: pulumi.String("172.16.0.0/24"),
})
if err != nil {
return err
}
defaultScalingGroup, err := ess.NewScalingGroup(ctx, "defaultScalingGroup", &ess.ScalingGroupArgs{
MinSize: pulumi.Int(0),
MaxSize: pulumi.Int(2),
ScalingGroupName: pulumi.String(name),
RemovalPolicies: pulumi.StringArray{
pulumi.String("OldestInstance"),
pulumi.String("NewestInstance"),
},
VswitchIds: pulumi.StringArray{
defaultSwitch.ID(),
},
})
if err != nil {
return err
}
_, err = ess.NewScalingConfiguration(ctx, "defaultScalingConfiguration", &ess.ScalingConfigurationArgs{
ScalingGroupId: defaultScalingGroup.ID(),
ImageId: pulumi.String(defaultImages.Images[0].Id),
InstanceType: pulumi.String(defaultInstanceTypes.InstanceTypes[0].Id),
SecurityGroupId: defaultSecurityGroup.ID(),
ForceDelete: pulumi.Bool(true),
Active: pulumi.Bool(true),
Enable: pulumi.Bool(true),
})
if err != nil {
return err
}
var defaultInstance []*ecs.Instance
for key0, _ := range 2 {
__res, err := ecs.NewInstance(ctx, fmt.Sprintf("defaultInstance-%v", key0), &ecs.InstanceArgs{
ImageId: pulumi.String(defaultImages.Images[0].Id),
InstanceType: pulumi.String(defaultInstanceTypes.InstanceTypes[0].Id),
SecurityGroups: pulumi.StringArray{
defaultSecurityGroup.ID(),
},
InternetChargeType: pulumi.String("PayByTraffic"),
InternetMaxBandwidthOut: pulumi.Int(10),
InstanceChargeType: pulumi.String("PostPaid"),
SystemDiskCategory: pulumi.String("cloud_efficiency"),
VswitchId: defaultSwitch.ID(),
InstanceName: pulumi.String(name),
})
if err != nil {
return err
}
defaultInstance = append(defaultInstance, __res)
}
_, err = ess.NewAttachment(ctx, "defaultAttachment", &ess.AttachmentArgs{
ScalingGroupId: defaultScalingGroup.ID(),
InstanceIds: pulumi.StringArray{
defaultInstance[0].ID(),
defaultInstance[1].ID(),
},
Force: pulumi.Bool(true),
})
if err != nil {
return err
}
return nil
})
}
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(name_regex="^ubuntu_18.*64",
most_recent=True,
owners="system")
default_network = alicloud.vpc.Network("defaultNetwork",
vpc_name=name,
cidr_block="172.16.0.0/16")
default_switch = alicloud.vpc.Switch("defaultSwitch",
vpc_id=default_network.id,
cidr_block="172.16.0.0/24",
zone_id=default_zones.zones[0].id)
default_security_group = alicloud.ecs.SecurityGroup("defaultSecurityGroup", vpc_id=default_network.id)
default_security_group_rule = alicloud.ecs.SecurityGroupRule("defaultSecurityGroupRule",
type="ingress",
ip_protocol="tcp",
nic_type="intranet",
policy="accept",
port_range="22/22",
priority=1,
security_group_id=default_security_group.id,
cidr_ip="172.16.0.0/24")
default_scaling_group = alicloud.ess.ScalingGroup("defaultScalingGroup",
min_size=0,
max_size=2,
scaling_group_name=name,
removal_policies=[
"OldestInstance",
"NewestInstance",
],
vswitch_ids=[default_switch.id])
default_scaling_configuration = alicloud.ess.ScalingConfiguration("defaultScalingConfiguration",
scaling_group_id=default_scaling_group.id,
image_id=default_images.images[0].id,
instance_type=default_instance_types.instance_types[0].id,
security_group_id=default_security_group.id,
force_delete=True,
active=True,
enable=True)
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_type=default_instance_types.instance_types[0].id,
security_groups=[default_security_group.id],
internet_charge_type="PayByTraffic",
internet_max_bandwidth_out=10,
instance_charge_type="PostPaid",
system_disk_category="cloud_efficiency",
vswitch_id=default_switch.id,
instance_name=name))
default_attachment = alicloud.ess.Attachment("defaultAttachment",
scaling_group_id=default_scaling_group.id,
instance_ids=[
default_instance[0].id,
default_instance[1].id,
],
force=True)
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 = alicloud.getZones({
availableDiskCategory: "cloud_efficiency",
availableResourceCreation: "VSwitch",
});
const defaultInstanceTypes = defaultZones.then(defaultZones => alicloud.ecs.getInstanceTypes({
availabilityZone: defaultZones.zones?[0]?.id,
cpuCoreCount: 2,
memorySize: 4,
}));
const defaultImages = alicloud.ecs.getImages({
nameRegex: "^ubuntu_18.*64",
mostRecent: true,
owners: "system",
});
const defaultNetwork = new alicloud.vpc.Network("defaultNetwork", {
vpcName: name,
cidrBlock: "172.16.0.0/16",
});
const defaultSwitch = new alicloud.vpc.Switch("defaultSwitch", {
vpcId: defaultNetwork.id,
cidrBlock: "172.16.0.0/24",
zoneId: defaultZones.then(defaultZones => defaultZones.zones?[0]?.id),
});
const defaultSecurityGroup = new alicloud.ecs.SecurityGroup("defaultSecurityGroup", {vpcId: defaultNetwork.id});
const defaultSecurityGroupRule = new alicloud.ecs.SecurityGroupRule("defaultSecurityGroupRule", {
type: "ingress",
ipProtocol: "tcp",
nicType: "intranet",
policy: "accept",
portRange: "22/22",
priority: 1,
securityGroupId: defaultSecurityGroup.id,
cidrIp: "172.16.0.0/24",
});
const defaultScalingGroup = new alicloud.ess.ScalingGroup("defaultScalingGroup", {
minSize: 0,
maxSize: 2,
scalingGroupName: name,
removalPolicies: [
"OldestInstance",
"NewestInstance",
],
vswitchIds: [defaultSwitch.id],
});
const defaultScalingConfiguration = new alicloud.ess.ScalingConfiguration("defaultScalingConfiguration", {
scalingGroupId: defaultScalingGroup.id,
imageId: defaultImages.then(defaultImages => defaultImages.images?[0]?.id),
instanceType: defaultInstanceTypes.then(defaultInstanceTypes => defaultInstanceTypes.instanceTypes?[0]?.id),
securityGroupId: defaultSecurityGroup.id,
forceDelete: true,
active: true,
enable: true,
});
const defaultInstance: alicloud.ecs.Instance[];
for (const range = {value: 0}; range.value < 2; range.value++) {
defaultInstance.push(new alicloud.ecs.Instance(`defaultInstance-${range.value}`, {
imageId: defaultImages.then(defaultImages => defaultImages.images?[0]?.id),
instanceType: defaultInstanceTypes.then(defaultInstanceTypes => defaultInstanceTypes.instanceTypes?[0]?.id),
securityGroups: [defaultSecurityGroup.id],
internetChargeType: "PayByTraffic",
internetMaxBandwidthOut: 10,
instanceChargeType: "PostPaid",
systemDiskCategory: "cloud_efficiency",
vswitchId: defaultSwitch.id,
instanceName: name,
}));
}
const defaultAttachment = new alicloud.ess.Attachment("defaultAttachment", {
scalingGroupId: defaultScalingGroup.id,
instanceIds: [
defaultInstance[0].id,
defaultInstance[1].id,
],
force: true,
});
Coming soon!
Create a Attachment Resource
new Attachment(name: string, args: AttachmentArgs, opts?: CustomResourceOptions);
@overload
def Attachment(resource_name: str,
opts: Optional[ResourceOptions] = None,
force: Optional[bool] = None,
instance_ids: Optional[Sequence[str]] = None,
scaling_group_id: Optional[str] = None)
@overload
def Attachment(resource_name: str,
args: AttachmentArgs,
opts: Optional[ResourceOptions] = None)
func NewAttachment(ctx *Context, name string, args AttachmentArgs, opts ...ResourceOption) (*Attachment, error)
public Attachment(string name, AttachmentArgs args, CustomResourceOptions? opts = null)
public Attachment(String name, AttachmentArgs args)
public Attachment(String name, AttachmentArgs args, CustomResourceOptions options)
type: alicloud:ess:Attachment
properties: # The arguments to resource properties.
options: # 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.
- resource_name str
- The unique name of the resource.
- args AttachmentArgs
- The arguments to resource properties.
- opts ResourceOptions
- Bag of options to control 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.
- name String
- The unique name of the resource.
- args AttachmentArgs
- The arguments to resource properties.
- options 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 Architecture and Concepts 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 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 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 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 Sequence[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.
- 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 Boolean
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:
- 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 string
The provider-assigned unique ID for this managed resource.
- id str
The provider-assigned unique ID for this managed resource.
- id String
The provider-assigned unique ID for this managed resource.
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): Attachment
@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
force: Optional[bool] = None,
instance_ids: Optional[Sequence[str]] = None,
scaling_group_id: Optional[str] = None) -> Attachment
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)
public static Attachment get(String name, Output<String> id, AttachmentState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
- 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.
- 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.
- 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 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 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 Sequence[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 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<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.
Import
ESS attachment can be imported using the id or scaling group id, e.g.
$ pulumi import alicloud:ess/attachment:Attachment example asg-abc123456
Package Details
- Repository
- https://github.com/pulumi/pulumi-alicloud
- License
- Apache-2.0
- Notes
This Pulumi package is based on the
alicloud
Terraform Provider.