Amazon ECS on Spot Fleet Terraform module
A terraform module for creating Spot Fleet instances to attach to an existing ECS cluster. This is a demo repository. The outline is as following:
- Bid on Spot Fleet and launch instances that spans two AZs.
- Started instances constitute an ECS cluster.
- Invoked containers support dynamic port mapping by ALB.
Module Input Variables
Required
vpc
- VPC id for ECS clustersubnets
- List of subnet ids for ECS cluster, please choose 2 subnetskey_name
- Name of key pair for SSH login to ECS cluster instancesecs_cluster_name
- Name of the ECS cluster to add spot instances to
Optional
ami
- ECS cluster instance AMI id, default is Amazon ECS-optimized AMI inus-east-1
app_name
- Your application name, default isdemo-app
image
- Your docker image name, default it ECS PHP Simple Appcontainer_port
- Port number exposed by container, default is 80service_count
- Number of containers, default is 3cpu_unit
- Number of cpu_units for container, default is 128memory
- Number of memory for container, default is 128spot_prices
- Bid amount to spot fleet, please choose 2 prices, default is$0.03
strategy
- Instance placement strategy name, default isdiversified
instance_count
- Number of instances, default is 3instance_type
- Instance type launched by Spot Fleet. default ism3.medium
volume_size
- Root volume size, default is 16https
- Whether the load balancer should listen to https requests, default isfalse
app_certificate_arn
- The ARN of the ssl certificate, default is emptyapp_ssl_policy
- The ssl policy, default isELBSecurityPolicy-2015-05
valid_until
- limit of Spot Fleet request, default is2020-12-15T00:00:00Z
Usage
Like other modules, you can easily start ECS cluster by adding this module to your template with required parameters.
provider "aws" {
region = "us-east-1"
}
module "ecs_on_spotfleet" {
source = "github.com/wata727/tf_aws_ecs_on_spotfleet"
vpc = "vpc-12345"
subnets = ["subnet-12345", "subnet-abcde"]
spot_prices = ["0.03", "0.02"]
key_name = "demo-app"
}
output "endpoint" {
value = "${module.ecs_on_spotfleet.endpoint}"
}
Customize
This module is very simple, please remodel and create your own module.