hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.81k stars 9.16k forks source link

aws_spot_fleet_request: add support for launch-before-terminate rebalance strategy #22634

Open partamonov opened 2 years ago

partamonov commented 2 years ago

Community Note

Description

Now only supported type for capacity rebalance is launch, but that would be handy to support launch-before-terminate

New or Affected Resource(s)

Potential Terraform Configuration

resource "aws_spot_fleet_request" "fleet" {
  ...
  spot_maintenance_strategies {
      capacity_rebalance {
          replacement_strategy = "launch-before-terminate"
          timeout = 300
      }
   }
}

Link to AWS documentation

sjonpaulbrown commented 2 years ago

@partamonov have you tried using the "launch-before-terminate" value for the replacement_strategy. After looking at the available values for the replacement_strategy, it looks like "launch-before-terminate" before terminate is available is a value.

The documentation may need to need to be updated, but I believe this is already supported as the supported strategies are originating from the Golang SDK which has been updated with this value.

partamonov commented 2 years ago

@sjonpaulbrown, yes I tried. It fails with missing mandatory timeout field, as with launch-before-terminate timeout is required field. My idea was exactly to try it, as I thought that default 120 seconds might work for me, but that field is not present in terraform input data, so request fails

type SpotCapacityRebalance struct {

    // The replacement strategy to use. Only available for fleets of type maintain.
    //
    // launch - Spot Fleet launches a new replacement Spot Instance when a rebalance
    // notification is emitted for an existing Spot Instance in the fleet. Spot
    // Fleet does not terminate the instances that receive a rebalance notification.
    // You can terminate the old instances, or you can leave them running. You are
    // charged for all instances while they are running.
    //
    // launch-before-terminate - Spot Fleet launches a new replacement Spot Instance
    // when a rebalance notification is emitted for an existing Spot Instance in
    // the fleet, and then, after a delay that you specify (in TerminationDelay),
    // terminates the instances that received a rebalance notification.
    ReplacementStrategy *string `locationName:"replacementStrategy" type:"string" enum:"ReplacementStrategy"`

    // The amount of time (in seconds) that Amazon EC2 waits before terminating
    // the old Spot Instance after launching a new replacement Spot Instance.
    //
    // Required when ReplacementStrategy is set to launch-before-terminate.
    //
    // Not valid when ReplacementStrategy is set to launch.
    //
    // Valid values: Minimum value of 120 seconds. Maximum value of 7200 seconds.
    TerminationDelay *int64 `locationName:"terminationDelay" type:"integer"`
    // contains filtered or unexported fields
}
sjonpaulbrown commented 2 years ago

Ah, that makes sense. So, the TerminationDelay field will need to be conditionally set when launch-before-terminate is defined as the replacement_strategy. This is helpful context to have and explains what needs to be updated to support this strategy.

nglcasanova commented 2 years ago

A spot fleet request with the "launch-before-terminate" replacement_strategy cannot be created using terraform-provider-aws version 4.14.0...

kunalnanda commented 1 year ago

This is a must have for us. I cannot use Terraform for Spot Fleet Requests as we need launch-before-terminate. I hate using Cloudformation, so would prefer if we can get some traction on this please.