Show / Hide Table of Contents

Class 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,
    });
}

}
Inheritance
System.Object
Resource
CustomResource
Attachment
Inherited Members
CustomResource.Id
Resource.GetResourceType()
Resource.GetResourceName()
Resource.Urn
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Pulumi.AliCloud.Ess
Assembly: Pulumi.AliCloud.dll
Syntax
public class Attachment : CustomResource

Constructors

View Source

Attachment(String, AttachmentArgs, CustomResourceOptions)

Create a Attachment resource with the given unique name, arguments, and options.

Declaration
public Attachment(string name, AttachmentArgs args, CustomResourceOptions options = null)
Parameters
Type Name Description
System.String name

The unique name of the resource

AttachmentArgs args

The arguments used to populate this resource's properties

CustomResourceOptions options

A bag of options that control this resource's behavior

Properties

View Source

Force

Whether to remove forcibly "AutoCreated" ECS instances in order to release scaling group capacity "MaxSize" for attaching ECS instances. Default to false.

Declaration
public Output<bool?> Force { get; }
Property Value
Type Description
Output<System.Nullable<System.Boolean>>
View Source

InstanceIds

ID of the ECS instance to be attached to the scaling group. You can input up to 20 IDs.

Declaration
public Output<ImmutableArray<string>> InstanceIds { get; }
Property Value
Type Description
Output<System.Collections.Immutable.ImmutableArray<System.String>>
View Source

ScalingGroupId

ID of the scaling group of a scaling configuration.

Declaration
public Output<string> ScalingGroupId { get; }
Property Value
Type Description
Output<System.String>

Methods

View Source

Get(String, Input<String>, AttachmentState, CustomResourceOptions)

Get an existing Attachment resource's state with the given name, ID, and optional extra properties used to qualify the lookup.

Declaration
public static Attachment Get(string name, Input<string> id, AttachmentState state = null, CustomResourceOptions options = null)
Parameters
Type Name Description
System.String name

The unique name of the resulting resource.

Input<System.String> id

The unique provider ID of the resource to lookup.

AttachmentState state

Any extra arguments used during the lookup.

CustomResourceOptions options

A bag of options that control this resource's behavior

Returns
Type Description
Attachment
  • View Source
Back to top Copyright 2016-2020, Pulumi Corporation.