Resource: aws_ec2_fleet

Provides a resource to manage EC2 Fleets.

Example Usage

resource "aws_ec2_fleet" "example" {
  launch_template_config {
    launch_template_specification {
      launch_template_id = aws_launch_template.example.id
      version            = aws_launch_template.example.latest_version
    }
  }

  target_capacity_specification {
    default_target_capacity_type = "spot"
    total_target_capacity        = 5
  }
}

Argument Reference

This resource supports the following arguments:

launch_template_config

Describes a launch template and overrides.

launch_template_specification

The launch template to use. You must specify either the launch template ID or launch template name in the request.

override

Any parameters that you specify override the same parameters in the launch template. For fleets of type request and maintain, a maximum of 300 items is allowed across all launch templates.

Example:

resource "aws_ec2_fleet" "example" {
  # ... other configuration ...

  launch_template_config {
    # ... other configuration ...

    override {
      instance_type     = "m4.xlarge"
      weighted_capacity = 1
    }

    override {
      instance_type     = "m4.2xlarge"
      weighted_capacity = 2
    }
  }
}
instance_requirements

The attributes for the instance types. For a list of currently supported values, please see 'InstanceRequirementsRequest'.

This configuration block supports the following:

on_demand_options

spot_options

maintenance_strategies

capacity_rebalance

target_capacity_specification

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Timeouts

Configuration options:

Import

In Terraform v1.5.0 and later, use an import block to import aws_ec2_fleet using the Fleet identifier. For example:

import {
  to = aws_ec2_fleet.example
  id = "fleet-b9b55d27-c5fc-41ac-a6f3-48fcc91f080c"
}

Using terraform import, import aws_ec2_fleet using the Fleet identifier. For example:

% terraform import aws_ec2_fleet.example fleet-b9b55d27-c5fc-41ac-a6f3-48fcc91f080c