AWS Batch Compute Environment Terraform Module

Creates a AWS Batch compute environment. Compute environments contain the Amazon ECS container instances that are used to run containerized batch jobs.

Note

FARGATE and FARGATE_SPOT type of Compute environments are not currently supported

Terraform versions

Terraform >=0.12

Usage

with out passing any subnets

data "aws_availability_zones" "available" {
  state = "available"
}

module "batch_compute_environment" {

  source = "QuiNovas/batch-compute-environment/aws"

  name                   = "test-terraform"
  type                   = "MANAGED"
  compute_resources_type = "SPOT"
  instance_type          = ["optimal"]
  min_vcpus              = 0
  desired_vcpus          = 0
  max_vcpus              = 16

  availability_zones     = data.aws_availability_zones.available.names
  cidr_block             = "10.0.0.0/16"

  tags = {
    Terraform = "true"
    Environment = "dev"
  }

}

with passing subnets

module "batch_compute_environment" {

  source = "QuiNovas/batch-compute-environment/aws"
  
  name                   = "test-terraform"
  type                   = "MANAGED"
  compute_resources_type = "SPOT"
  instance_type          = ["optimal"]
  min_vcpus              = 0
  desired_vcpus          = 0
  max_vcpus              = 16

  security_group_ids     = ["sg-1fd1106f"]
  subnets                = ["subnet-a59faaed", "subnet-60eef25c"]

  tags = {
    Terraform = "true"
    Environment = "dev"
  }

}

Service Roles

By default this module will provision new service roles for batch, ec2 and spot fleet if they are not passed through variables.

Network Resources

This module will create a VPC, a Internet Gateway, 2 or 3 Private subnets (one per az), 2 or 3 Public subnets (one per az), with 2 or 3 NATs in there respective az's/public subnets (along with necessary routing) If subnets are not passed in.

The subnets are created by using 4 bits for masking on the given CIDR. A list of availability_zones is necessary if you want the vpc and other network resources are created by module.

Inputs

Name Description Type Default Required
availability_zones The avaiability zones for the subnets of compute environment, Required if subnets created outside the module are not passed in. So that necessary networking resources are created list(string) [] no
bid_percentage Integer of minimum percentage that a Spot Instance price must be when compared with the On-Demand price for that Instance type before instances are launched. For example, if you bid percentage is 20% (20), then the Spot price must be bellow 20% of the current On-Demand price for that EC2 Instance. This parameter is required for SPOT compute environments number 100 no
cidr_block The CIDR block for the Compute environment VPC string "192.168.0.0/16" no
compute_resources_type The type of compute environment. Valid items are EC2 or SPOT string yes
desired_vcpus The desired number of EC2 vCPUS in the compute environment number 0 no
ec2_key_pair The EC2 key pair is used for instances launched in the compute environment string "" no
image_id The Amazon Machine Image (AMI) ID used for instances launched in the compute environment string "" no
instance_role The Amazon ECS instance role applied to Amazon EC2 instance in a computed environment, Module will create the role if not provided string "" no
instance_type A list of instance types that may be launched list(string) yes
launch_template The launch template to use for your compute resource list(object({launch_template_id, version })) [] no
launch_template_id Child variable of launch template Object string "" no
version Child variable of launch template Object string "" no
max_vcpus The maximum number of EC2 vCPUs that an environment can reach string yes
min_vcpus The minimum number of EC2 vCPUs that environment should maintain string yes
name The name of resources created, used either directly or as a prefix string yes
security_group_ids A list of EC2 security group that are associated with instances launched in the compuite environments list(string) yes
service_role The full Amazon Resource Name(ARN) of the IAM role that allows AES Batch to make calls to other AWS services on you behalf, If not provided module will create the role string "" no
spot_iam_fleet_role The Amazon Resource Name (ARN) of the Amazon EC2 Spot Fleet IAM role applied to a SPOT compute environment. This parameter is required for SPOT compute environment. When compute_resources_type is SPOT and if this role arn is not provided then module will create one string "" no
state The state of the compute environment. If the state id ENABLED, then the compute environment accepts jobs from a queue and can scale out automatically based on queues. Valid items are ENABLED or DISABLED. Default to ENABLED string "ENABLED" no
subnets A list of VPC subnets into which the compute resources are launched. list(string) [] no
tags Key-value pair tags to be applied to resource that are launched in the compute environment map(string) {} no
type The type of the compute environment. Valid items are MANAGED or UNMANAGED string yes

Outputs

Name Description
arn The arn of the created batch compute environment

Authors

Module is maintained by QuiNovas