pulumi / pulumi-aws-native

AWS Native Provider for Pulumi
Apache License 2.0
95 stars 17 forks source link

AutoScalingGroup update fails on launch template changes #1634

Open ixti opened 4 months ago

ixti commented 4 months ago

What happened?

When I change launch template, ASG update fails:

operation UPDATE failed with "InvalidRequest": To describe the launch template data for all your launch templates, for ‘--versions’ specify ‘$Latest’, ‘$Default’, or both, and omit ‘--launch-template-id’, ‘--launch-template-name’, and version numbers. To describe the launch template data for a specific launch template, specify ‘--launch-template-id’ or ‘--launch-template-name’, and for ‘--versions’ specify one or more of the following values: ‘$Latest’, ‘$Default’, or one or more version numbers. (Service: Ec2, Status Code: 400, Request ID: c7b8595f-6104-4b59-bd20-af789ccfb2b8)

Example

const userDataBase64Encoded = Buffer.from(`#!/bin/bash
echo 42
`).toString("base64");

const launchTemplate = new awsNative.ec2.LaunchTemplate("launch-template", {
  launchTemplateName: launchTemplateName,
  launchTemplateData: {
    blockDeviceMappings: blockDeviceMappings,
    iamInstanceProfile:  { arn: instanceProfile.arn },
    imageId:             amazonLinuxImageId,
    instanceType:        instanceType,
    keyName:             sshKeyName,
    metadataOptions:     metadataOptions,
    networkInterfaces:   [{ associatePublicIpAddress: false, deviceIndex: 0, groups: [securityGroupId] }],
    userData:            userDataBase64Encoded
  }
});

const autoScalingGroup = new awsNative.autoscaling.AutoScalingGroup("asg", {
  autoScalingGroupName:      `${pulumi.getProject()}-${pulumi.getStack()}`,
  healthCheckGracePeriod:    300,
  healthCheckType:           "ELB",
  instanceMaintenancePolicy: { minHealthyPercentage: 90, maxHealthyPercentage: 190 },
  launchTemplate:            { launchTemplateId: launchTemplate.launchTemplateId, version: launchTemplate.latestVersionNumber },
  maxSize:                   "2",
  metricsCollection:         [{ granularity: "1Minute", metrics: ["GroupInServiceInstances"] }],
  minSize:                   "1",
  targetGroupArns:           [targetGroupArn],
  vpcZoneIdentifier:         privateSubnetIds
});

After changing updating userData - it causes (correctly) update of the ASG as well, but the updte fails with the above message.

Output of pulumi about

CLI          
Version      3.124.0
Go Version   go1.22.5
Go Compiler  gc

Plugins
KIND      NAME        VERSION
resource  aws         6.44.0
resource  aws-native  0.110.0
language  nodejs      unknown
resource  random      4.16.3

Host     
OS       gentoo
Version  2.15
Arch     x86_64

Backend        
Name           evil-eurasier
URL            s3://***
User           ixti
Organizations  
Token type     personal

Dependencies:
NAME                VERSION
@pulumi/aws-native  0.111.0
@pulumi/aws         6.44.0
@pulumi/pulumi      3.124.0
@pulumi/random      4.16.3
@types/node         20.14.10

Additional context

As a workaround - switched to aws classic for the ASG resource:

const autoScalingGroup = new aws.autoscaling.Group("asg", {
  enabledMetrics:            ["GroupInServiceInstances"],
  healthCheckGracePeriod:    300,
  healthCheckType:           "ELB",
  instanceMaintenancePolicy: { minHealthyPercentage: 90, maxHealthyPercentage: 190 },
  launchTemplate:            { id: launchTemplate.id, version: launchTemplate.latestVersionNumber },
  maxSize:                   2,
  metricsGranularity:        "1Minute",
  minSize:                   1,
  name:                      `${pulumi.getProject()}-${pulumi.getStack()}`,
  targetGroupArns:           [targetGroupArn],
  vpcZoneIdentifiers:        privateSubnetIds
}, {
  dependsOn: [launchTemplate],
  provider:  awsClassicUsWest2Provider
});

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

ixti commented 4 months ago

An alternative workaround would be to create autoscaling group name using random provider with userData as keepers.

corymhall commented 4 months ago

@ixti thanks for raising this! It looks like it is an issue with the CloudControl API so I've created an issue in the cloudformation-roadmap repo.

ytimenkov commented 2 months ago

@ixti Got into the same issue. Could you please elaborate on "An alternative workaround would be to create autoscaling group name using random provider with userData as keepers." ?

I put replaceOnChanges: ["launchTemplate"], but it really sucks because it kills all the instances... Using classic is an option (I still have it to provision route53 entries), but I don't really like to go back.

ixti commented 1 month ago

@ixti Got into the same issue. Could you please elaborate on "An alternative workaround would be to create autoscaling group name using random provider with userData as keepers." ?

Frankly, it was only a hypothesis that I never tried to check. And retroactively reading my own message, I can't even tell what I was thinking about when I wrote that possible alternative approach. :D Sorry.