Elastic Beanstalk

This post demonstrates how to create an Elastigroup integrated with Elastic Beanstalk using the Spotinst Terraform plugin.

This post assumes that you already have a Spotinst account and went through Spotinst Terraform Installation & Configuration
Example Usage – Beanstalk Elastigroup

Create an elastigroup based on an existing beanstalk environment

resource "spotinst_elastigroup_aws_beanstalk" "elastigoup-aws-beanstalk" {
  name    = "example-elastigroup-beanstalk"
  region  = "us-east-1"
  product = "Linux/UNIX"

  min_size         = 0
  max_size         = 4
  desired_capacity = 2

  beanstalk_environment_name = "example-env"
  beanstalk_environment_id   = "e-example"
  instance_types_spot        = ["t2.micro", "t2.medium", "t2.large"]
  maintenance = "START"
  
  deployment_preferences = {
    automatic_roll        = true
    batch_size_percentage = 100
    grace_period          = 90
      strategy = {
        action                 = "REPLACE_SERVER"
        should_drain_instances = true
      }
  }

  managed_actions = {
    platform_update = {
      perform_at   = "timeWindow"
      time_window  = "Mon:23:50-Tue:00:20"
      update_level = "minorAndPatch"
    }
  }
}

Argument Reference

Parameter Type Description
name * String

The name of the elastigroup.

Example: "my_group"
region * String

The Beanstalk environment region.

Example: us-east-1
description String

The group description.

product * String

Operation system type. Valid values: "Linux/UNIX", "SUSE Linux", "Windows". For EC2 Classic instances: "Linux/UNIX (Amazon VPC)", "SUSE Linux (Amazon VPC)", "Windows (Amazon VPC)".

Example: Linux/UNIX
min_size * Integer

The minimum number of instances the group should have at any time.

Example: 1
max_size * Integer

The maximum number of instances the group should have at any time.

Example: 4
desired_capacity * Integer

The desired number of instances the group should have at any time.

Example: 2
beanstalk_environment_name String

The name of an existing Beanstalk environment.

Example: Example-env
beanstalk_environment_id String

The id of an existing Beanstalk environment.

Example: e-example
instance_types_spot * Array<String>

One or more instance types. To maximize the availability of Spot instances, select as many instance types as possible.

Example: ["t2.micro", "t2.medium", "t2.large"]
maintenance String

Send a signal to either start or end beanstalk maintenance mode. Can be "START", "END", or "SATUS"

Example: START
deployment_preferences Object

Preferences when performing a roll.

deployment_preferences.automatic_roll * Boolean

Should roll perform automatically.

Example: true
deployment_preferences.batch_size_percentage * Integer

Percent size of each batch.

Example: 100
deployment_preferences.grace_period * Integer

Amount of time to wait between batches (in seconds).

Example: 90
deployment_preferences.strategy Object

Strategy parameters.

deployment_preferences.strategy.action * String

Action to take.

Example: REPLACE_SERVER
deployment_preferences.strategy.should_drain_instances * Boolean

Boolean value if to wait to drain instance.

Example: true
managed_actions Object

Managed Actions parameters.

managed_actions.platform_update Object

Platform Update parameters.

managed_actions.platform_update.perform_at * String

Actions to perform (options: timeWindow, never)

Example: timeWindow
managed_actions.platform_update.time_window * String

Time Window for when action occurs.

Example: Mon:23:50-Tue:00:20
managed_actions.platform_update.update_level * String

Level to update

Example: minorAndPatch

Scheduled Tasks

Each scheduled_task supports the following:

  • task_type – (Required) The task type to run. Supported task types are: "scale""backup_ami""roll""scaleUp""percentageScaleUp""scaleDown""percentageScaleDown""statefulUpdateCapacity".
  • cron_expression – (Optional; Required if not using frequency) A valid cron expression. The cron is running in UTC time zone and is in Unix cron format.
  • start_time – (Optional; Format: ISO 8601) Set a start time for one time tasks.
  • frequency – (Optional; Required if not using cron_expression) The recurrence frequency to run this task. Supported values are "hourly""daily""weekly" and "continuous".
  • scale_target_capacity – (Optional) The desired number of instances the group should have.
  • scale_min_capacity – (Optional) The minimum number of instances the group should have.
  • scale_max_capacity – (Optional) The maximum number of instances the group should have.
  • is_enabled – (Optional, Default: true) Setting the task to being enabled or disabled.
  • target_capacity – (Optional; Only valid for statefulUpdateCapacity) The desired number of instances the group should have.
  • min_capacity – (Optional; Only valid for statefulUpdateCapacity) The minimum number of instances the group should have.
  • max_capacity – (Optional; Only valid for statefulUpdateCapacity) The maximum number of instances the group should have.
  • batch_size_percentage – (Optional; Required when the task_type is "roll".) The percentage size of each batch in the scheduled deployment roll.
  • grace_period – (Optional) The period of time (seconds) to wait before checking a batch’s health after it’s deployment.
  • adjustment – (Optional; Min 1) The number of instances to add or remove.
  • adjustment_percentage – (Optional; Min 1) The percentage of instances to add or remove.

Usage:

scheduled_task {
  task_type             = "backup_ami"
  cron_expression       = ""
  start_time            = "1970-01-01T01:00:00Z"
  frequency             = "hourly"
  scale_target_capacity = 5
  scale_min_capacity    = 0
  scale_max_capacity    = 10
  is_enabled            = false
  target_capacity       = 5
  min_capacity          = 0
  max_capacity          = 10
  batch_size_percentage = 33
  grace_period          = 300
}

Attributes Reference


Attribute Type Description
id String

The elastigroup ID. This attribute is generated as a result of importing the beanstalk environment.

Example: sig-123456