https://pulumi.com logo
#general
Title
# general
c

clever-glass-42863

06/28/2022, 6:58 PM
Greetings, is there a way to invoke the
attach-instances
command from the AWS package so we can attach an EC2 instance to an AutoScaleGroup? I see the Attachment resource, however I don't see the parameters to specify a launched EC2 instance. Any help would be appreciated.
b

billowy-army-68599

06/28/2022, 7:16 PM
I don't believe this is supported at the moment. Can youy talk more about what you're trying to do?
c

clever-glass-42863

06/28/2022, 7:19 PM
Thanks for the reply. We have a EC2 launch type service that runs game servers via UDP. The EC2 itself is in
host
networkMode which then requires a
distinctInstance
configuration from the auto scale perspective. This is fine, except when trying to do rolling updates. Since we have a desired count for the service, if we are currently servicing our desired count, the auto scale group doesn't create an additional EC2 instance to account for the task placement. Therefore our strategy was to always spin up n+ EC2 instances as needed to serve the rolling deployment. The use case then is to attach the newly created EC2 instance (outside of the scale group) to the scaling group so that it is tracked appropriately.
AWS supports this mechanism via the GUI and CLI. However, I do not see a matching Terraform resource either.
b

billowy-army-68599

06/28/2022, 7:21 PM
that's a great run down, appreciate the insight!
if it's not in the tf provider, we won't have support for it It doesn't appear to be in the cloud control API yet either: https://www.pulumi.com/registry/packages/aws-native/api-docs/autoscaling/
c

clever-glass-42863

06/28/2022, 7:23 PM
Sounds good. We'll find a workaround. I appreciate the quick response
Here is a non-pulumi workaround in C# if anyone runs into this. It does require the use of the Amazon Sdk
Copy code
// attach-instances hack work around...
_ = Output.Tuple(ec2Instance.Id, clusterAutoScalingGroup.Name).Apply(async x =>
{
    using (var client = new Amazon.AutoScaling.AmazonAutoScalingClient(Amazon.RegionEndpoint.USWest1))
    {
        // This +1 the desired capacity, so you may want to wait for deploymenet then reduce the desired capacity...
        await client.AttachInstancesAsync(new Amazon.AutoScaling.Model.AttachInstancesRequest
        {
            InstanceIds = new List<string> { x.Item1 },
            AutoScalingGroupName = x.Item2
        });
    }

    // We don't care about the results...
    return string.Empty;
});
👍 1
7 Views