Terraform-provider-aws: Capacity-optimized allocation strategy for Amazon EC2 Spot Instances

Created on 13 Aug 2019  路  2Comments  路  Source: hashicorp/terraform-provider-aws

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

New capacity-optimized allocation strategy for EC2 Auto Scaling and EC2 Fleet.

New or Affected Resource(s)

Potential Terraform Configuration

resource "aws_autoscaling_group" "example" {
  mixed_instances_policy {
    instances_distribution {
      spot_allocation_strategy = "capacity-optimized"
    }
  }
}

resource "aws_ec2_fleet" "example" {
  spot_option {
    allocation_strategy = "capacityOptimized"
  }
}

resource "aws_spot_fleet_request" "example" {
  allocation_strategy = "capacityOptimized"
}

References

Announcement.
Blog post.

enhancement servicautoscaling servicec2

Most helpful comment

For other people finding this. The instances_distribution block for my Autoscaling Group looks like this now:

     instances_distribution {
       on_demand_percentage_above_base_capacity = 0
       spot_instance_pools = 0
       spot_allocation_strategy = "capacity-optimized"
     }

All 2 comments

In the interim, I've tried capacity-optimized in ASG and seems to be working well (no changes required).

From what I've checked so far there are differences in the implementation. EC2 Fleet, Spot Fleet and Auto Scaling Groups take slightly different approach.

Auto Scaling Groups, just pass the allocation strategy string through and does not validate the schema. For anyone applying it to an existing ASG config, bear in mind that spot_instance_pools is not compatible with capacity-optimized (link to documentation), meaning you will need to remove the spot_instance_pools section to make capacity-optimized to work.

For EC2 fleet, as I expected after checking the code, I got a validation error. Changes will be required to support it.

Error: expected spot_options.0.allocation_strategy to be one of [diversified lowestPrice], got capacityOptimized

  on ec2_fleet.tf line 22, in resource "aws_ec2_fleet" "aws_fleet_example":
  22: resource "aws_ec2_fleet" "aws_fleet_example" {

I haven't had a chance yet to test Spot Fleet, but my understanding is that there is no validation, just a pass-through the allocation strategy, so for as long as the instance_pools_to_use_count is not provided, my guess it it should work.

For other people finding this. The instances_distribution block for my Autoscaling Group looks like this now:

     instances_distribution {
       on_demand_percentage_above_base_capacity = 0
       spot_instance_pools = 0
       spot_allocation_strategy = "capacity-optimized"
     }
Was this page helpful?
0 / 5 - 0 ratings