This page demonstrates how to create an Ocean ECS cluster on AWS using the Spotinst Terraform plugin.

This post assumes that you already have a Spotinst account and went through Spotinst Terraform Installation & Configuration

Example Usage – Ocean ECS Cluster
resource "spotinst_ocean_ecs" "example" {
    region = "us-west-2"
    name = "terraform-ecs-cluster"
    cluster_name = "terraform-ecs-cluster"
    min_size         = "0"
    max_size         = "1000"
    desired_capacity = "500"
    subnet_ids = ["subnet-12345"]
    whitelist = ["t1.micro", "m1.small"]
    image_id = "ami-12345"
    security_group_ids = ["sg-12345"]
    key_pair = "keyPair"
    user_data = "IyEvYmluL2Jhc2gKZWNobyB0ZXJyYWZvcm0tZWNzLWNsdXN0ZXIgPj4gL2V0Yy9lY3MvZWNzLmNvbmZpZw=="
    iam_instance_profile = "arn:aws:iam::12345:instance-profile/ecsInstanceProfile"
    associate_public_ip_address = false  

    autoscaler {
      cooldown = 240
      headroom {
        cpu_per_unit = 1024
        memory_per_unit = 512
        num_of_units = 2
      down {
        max_scale_down_percentage = 20
      is_auto_config = false
      is_enabled = false
      resource_limits {
        max_vcpu = 1
        max_memory_gib = 2

    update_policy {
      should_roll = true
      roll_config {
        batch_size_percentage = 100


Argument Reference

Parameter Type Description
name * String

The Ocean cluster name.

Example: ocean-ecs-cluster
cluster_name * String

The ECS cluster name.

Example: terraform-ecs-cluster
region * String

The region the cluster will run in.

Example: us-west-2
max_size Integer

The upper limit of instances the cluster can scale up to.

Example: 1000
Default: 1000
min_size Integer

The lower limit of instances the cluster can scale down to.

Example: 1
desired_capacity Integer

The number of instances to launch and maintain in the cluster.

Example: 2
subnet_ids * Array<String>

A comma-separated list of subnet identifiers for the Ocean cluster. Subnet IDs should be configured with auto assign public ip.

Example: ["subnet-12345"]
whitelist Array<String>

Instance types allowed in the Ocean cluster. Cannot be configured if `blacklist` is configured.

Example: ["t1.micro", "m1.small"]
blacklist Array<String>

Instance types not allowed in the Ocean cluster. Cannot be configured if `whitelist` is configured.

Example: ["t1.micro", "m1.small"]
image_id * String

ID of the image used to launch the instances.

Example: ami-12345
security_group_ids * Array<String>

One or more security group ids.

Example: ["sg-123456", "sg-98765"]
key_pair String

The key pair to attach the instances.

Example: myKey
user_data String

Base64-encoded MIME user data to make available to the instances.

Example: echo hello world
iam_instance_profile String

The instance profile IAM role.

Example: iam-profile
associate_public_ip_address Boolean

Configure public IP address allocation.

Example: true
Default: false
draining_timeout Integer

The time in seconds, the instance is allowed to run while detached from the ELB. This is to allow the instance time to be drained from incoming TCP connections before terminating it, during a scale down operation.

Example: 120
monitoring Boolean

Enable detailed monitoring for cluster. Flag will enable Cloud Watch detailed monitoring (one minute increments). Note: there are additional hourly costs for this service based on the region used.

Example: true
ebs_optimized Boolean

Enable "EBS optimized" flag for cluster. Flag will enable optimized capacity for high bandwidth connectivity to the EB service for non EBS optimized instance types. For instances that are EBS optimized this flag will be ignored.

Example: true
autoscaler Object

Describes the Ocean ECS autoscaler.

autoscaler.is_enabled Boolean

Enable the Ocean ECS autoscaler.

Example: true
autoscaler.is_auto_config Boolean

Automatically configure and optimize headroom resources.

Example: true
autoscaler.cooldown Integer

Cooldown period between scaling actions.

Example: 300
Default: null
autoscaler.headroom Object

Spare resource capacity management enabling fast assignment of tasks without waiting for new resources to launch.

autoscaler.headroom.cpu_per_unit Integer

Optionally configure the number of CPUs to allocate the headroom. CPUs are denoted in millicores, where 1000 millicores = 1 vCPU.

Example: 1024
autoscaler.headroom.memory_per_unit Integer

Optionally configure the amount of memory (MB) to allocate the headroom.

Example: 512
autoscaler.headroom.num_of_units Integer

The number of units to retain as headroom, where each unit has the defined headroom CPU and memory.

Example: 2
autoscaler.down Object

Auto Scaling scale down operations.

autoscaler.down.max_scale_down_percentage Integer

Would represent the maximum % to scale-down. Number between 1-100

Example: 20
autoscaler.resource_limits Object

Optionally set upper and lower bounds on the resource usage of the cluster.

autoscaler.resource_limits.max_vcpu Integer

The maximum cpu in vCPU units that can be allocated to the cluster.

Example: 1024
autoscaler.resource_limits.max_memory_gib Integer

The maximum memory in GiB units that can be allocated to the cluster.

Example: 20
tags Object

Optionally adds tags to instances launched in an Ocean cluster.

tags.key String

The tag key.

Example: fakeKey
tags.value String

The tag value.

Example: fakeValue
update_policy Object

While used, you can control whether the group should perform a deployment after an update to the configuration.

update_policy.should_roll * Boolean

Enables roll on update.

Example: true
update_policy.roll_config * Object

Roll parameters

update_policy.roll_config.batch_size_percentage * Integer

Sets the percentage of the cluster capacity to deploy in each batch.

Example: 33