pulumi / pulumi-awsx

AWS infrastructure best practices in component form!
https://www.pulumi.com/docs/guides/crosswalk/aws/
Apache License 2.0
227 stars 104 forks source link

Cannot launch auto scaling group with spot instances #645

Open vedantroy opened 3 years ago

vedantroy commented 3 years ago

I am trying to launch a ECS cluster that is backed by an auto-scaling group that uses spot instances.

To do this, I use the following code:

const projectName = pulumi.getProject();

const cluster = new awsx.ecs.Cluster(projectName, {
    tags: {
        ManagedBy: "Pulumi"
    }
})

const asg = cluster.createAutoScalingGroup(projectName, {
    launchConfigurationArgs: {
        // Deep Learning AMI (Ubuntu 18.04) Version 40.0
        imageId: "ami-09f77b37a0d32243a",
        instanceType: aws.ec2.InstanceType.P3_2XLarge,
        rootBlockDevice: {
            // unit = GB
            volumeSize: 32,
        },
        //placementTenancy: undefined,
        ebsBlockDevices: [],
        // p3.2xlarge on-demand price is $3.06
        // https://aws.amazon.com/ec2/pricing/on-demand/
        // TODO: Automate getting this value
        spotPrice: '306'
    },
    templateParameters: {
        minSize: 0,
        maxSize: 5,
        defaultCooldown: 10,
    }
})

Expected behavior

Something akin to this should work (a ecs cluster should be created that is backed by an auto-scaling group that launches spot instances).

Current behavior

Running pulumi up results in the following error: "* Error creating launch configuration: ValidationError: Placement tenancy is not supported for spot instances.".

I tried explicitly setting placementTenancy to undefined, but that did not work either.

Steps to reproduce

The code is @ the top of this post.

Context (Environment)

I want to launch ECS clusters backed by spot instances, and I can't do this with Pulumi right now.

leezen commented 3 years ago

This is currently a limitation of the underlying implementation in how launch configurations get created: https://github.com/pulumi/pulumi-awsx/blob/5dab49f887e3fdfc20e008bdeb2c27a2ed4dda96/nodejs/awsx/autoscaling/launchConfiguration.ts#L59

kororo commented 3 years ago

@leezen, correct me if I am wrong, is the solution to allow the spot by allowing the value as undefined?

placementTenancy: args.placementTenancy,

Currently, from my understanding, the only workaround for me is to create from scratch:

keen to know whether it is possible to allow undefined value?

Thanks

leezen commented 3 years ago

@kororo That sounds right, though I haven't had a chance to trace through the code to verify that that will work as intended. Definitely open to taking a PR here!