pulumi_wasm_providers_aws_mini::ec2

Module spot_fleet_request

source
Expand description

Provides an EC2 Spot Fleet Request resource. This allows a fleet of Spot instances to be requested on the Spot market.

**NOTE AWS strongly discourages the use of the legacy APIs called by this resource. We recommend using the EC2 Fleet or Auto Scaling Group resources instead.

§Example Usage

§Using launch specifications

resources:
  # Request a Spot fleet
  cheapCompute:
    type: aws:ec2:SpotFleetRequest
    name: cheap_compute
    properties:
      iamFleetRole: arn:aws:iam::12345678:role/spot-fleet
      spotPrice: '0.03'
      allocationStrategy: diversified
      targetCapacity: 6
      validUntil: 2019-11-04T20:44:20Z
      launchSpecifications:
        - instanceType: m4.10xlarge
          ami: ami-1234
          spotPrice: '2.793'
          placementTenancy: dedicated
          iamInstanceProfileArn: ${example.arn}
        - instanceType: m4.4xlarge
          ami: ami-5678
          keyName: my-key
          spotPrice: '1.117'
          iamInstanceProfileArn: ${example.arn}
          availabilityZone: us-west-1a
          subnetId: subnet-1234
          weightedCapacity: 35
          rootBlockDevices:
            - volumeSize: '300'
              volumeType: gp2
          tags:
            Name: spot-fleet-example

§Using launch templates

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let foo = launch_template::create(
        "foo",
        LaunchTemplateArgs::builder()
            .image_id("ami-516b9131")
            .instance_type("m1.small")
            .key_name("some-key")
            .name("launch-template")
            .build_struct(),
    );
    let fooSpotFleetRequest = spot_fleet_request::create(
        "fooSpotFleetRequest",
        SpotFleetRequestArgs::builder()
            .iam_fleet_role("arn:aws:iam::12345678:role/spot-fleet")
            .launch_template_configs(
                vec![
                    SpotFleetRequestLaunchTemplateConfig::builder()
                    .launchTemplateSpecification(SpotFleetRequestLaunchTemplateConfigLaunchTemplateSpecification::builder()
                    .id("${foo.id}").version("${foo.latestVersion}").build_struct())
                    .build_struct(),
                ],
            )
            .spot_price("0.005")
            .target_capacity(2)
            .valid_until("2019-11-04T20:44:20Z")
            .build_struct(),
    );
}

NOTE: This provider does not support the functionality where multiple subnet_id or availability_zone parameters can be specified in the same launch configuration block. If you want to specify multiple values, then separate launch configuration blocks should be used or launch template overrides should be configured, one per subnet:

§Using multiple launch specifications

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let foo = spot_fleet_request::create(
        "foo",
        SpotFleetRequestArgs::builder()
            .iam_fleet_role("arn:aws:iam::12345678:role/spot-fleet")
            .launch_specifications(
                vec![
                    SpotFleetRequestLaunchSpecification::builder().ami("ami-d06a90b0")
                    .availabilityZone("us-west-2a").instanceType("m1.small")
                    .keyName("my-key").build_struct(),
                    SpotFleetRequestLaunchSpecification::builder().ami("ami-d06a90b0")
                    .availabilityZone("us-west-2a").instanceType("m5.large")
                    .keyName("my-key").build_struct(),
                ],
            )
            .spot_price("0.005")
            .target_capacity(2)
            .valid_until("2019-11-04T20:44:20Z")
            .build_struct(),
    );
}

In this example, we use a dynamic block to define zero or more launch_specification blocks, producing one for each element in the list of subnet ids.

§Using multiple launch configurations

resources:
  foo:
    type: aws:ec2:LaunchTemplate
    properties:
      name: launch-template
      imageId: ami-516b9131
      instanceType: m1.small
      keyName: some-key
  fooSpotFleetRequest:
    type: aws:ec2:SpotFleetRequest
    name: foo
    properties:
      iamFleetRole: arn:aws:iam::12345678:role/spot-fleet
      spotPrice: '0.005'
      targetCapacity: 2
      validUntil: 2019-11-04T20:44:20Z
      launchTemplateConfigs:
        - launchTemplateSpecification:
            id: ${foo.id}
            version: ${foo.latestVersion}
          overrides:
            - subnetId: ${example.ids[0]}
            - subnetId: ${example.ids[1]}
            - subnetId: ${example.ids[2]}
    options:
      dependsOn:
        - ${["test-attach"]}
variables:
  example:
    fn::invoke:
      function: aws:ec2:getSubnets
      arguments:
        filters:
          - name: vpc-id
            values:
              - ${vpcId}

§Import

Using pulumi import, import Spot Fleet Requests using id. For example:

$ pulumi import aws:ec2/spotFleetRequest:SpotFleetRequest fleet sfr-005e9ec8-5546-4c31-b317-31a62325411e

Structs§

Functions§

  • Registers a new resource with the given unique name and arguments