terraform-aws-modules
terraform-aws-batch
HCL

Terraform module to create AWS Batch resources 🇺🇦

Last updated May 7, 2026
40
Stars
44
Forks
0
Issues
0
Stars/day
Attention Score
49
Language breakdown
HCL 100.0%
Files click to expand
README

AWS Batch Terraform module

Terraform module which creates AWS Batch resources.

Usage

See examples directory for working examples to reference:

module "batch" {
  source = "terraform-aws-modules/batch/aws"

compute_environments = { a_ec2 = { name_prefix = "ec2"

compute_resources = { type = "EC2" min_vcpus = 4 max_vcpus = 16 desired_vcpus = 4 instance_types = ["m5.large", "r5.large"]

securitygroupids = ["sg-f1d03a88"] subnets = ["subnet-30ef7b3c", "subnet-1ecda77b", "subnet-ca09ddbc"]

tags = { # This will set the name on the Ec2 instances launched by this compute environment Name = "example" Type = "Ec2" } } }

bec2spot = { nameprefix = "ec2spot"

compute_resources = { type = "SPOT" allocationstrategy = "SPOTCAPACITY_OPTIMIZED" bid_percentage = 20

min_vcpus = 4 max_vcpus = 16 desired_vcpus = 4 instance_types = ["m4.large", "m3.large", "r4.large", "r3.large"]

securitygroupids = ["sg-f1d03a88"] subnets = ["subnet-30ef7b3c", "subnet-1ecda77b", "subnet-ca09ddbc"]

tags = { # This will set the name on the Ec2 instances launched by this compute environment Name = "example-spot" Type = "Ec2Spot" } } } }

# Job queus and scheduling policies job_queues = { low_priority = { name = "LowPriorityEc2" state = "ENABLED" priority = 1

computeenvironmentorder = { 0 = { computeenvironmentkey = "bec2spot" } 1 = { computeenvironmentkey = "a_ec2" } }

tags = { JobQueue = "Low priority job queue" } }

high_priority = { name = "HighPriorityEc2" state = "ENABLED" priority = 99

computeenvironmentorder = { 0 = { computeenvironmentkey = "a_ec2" } }

fairsharepolicy = { compute_reservation = 1 sharedecayseconds = 3600

share_distribution = [{ share_identifier = "A1*" weight_factor = 0.1 }, { share_identifier = "A2" weight_factor = 0.2 }] }

tags = { JobQueue = "High priority job queue" } } }

job_definitions = { example = { name = "example" propagate_tags = true

container_properties = jsonencode({ command = ["ls", "-la"] image = "public.ecr.aws/runecast/busybox:1.33.1" resourceRequirements = [ { type = "VCPU", value = "1" }, { type = "MEMORY", value = "1024" } ] logConfiguration = { logDriver = "awslogs" options = { awslogs-group = "/aws/batch/example" awslogs-region = "us-east-1" awslogs-stream-prefix = "ec2" } } })

attemptdurationseconds = 60 retry_strategy = { attempts = 3 evaluateonexit = { retry_error = { action = "RETRY" onexitcode = 1 } exit_success = { action = "EXIT" onexitcode = 0 } } }

tags = { JobDefinition = "Example" } } }

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

Examples

Examples codified under the examples are intended to give users references for how to use the module(s) as well as testing/validating changes to the source code of the module. If contributing to the project, please be sure to make any appropriate updates to the relevant examples to allow maintainers to test your changes and to keep the examples up to date for users. Thank you!

Requirements

| Name | Version | |------|---------| | terraform | >= 1.5.7 | | aws | >= 6.28 |

Providers

| Name | Version | |------|---------| | aws | >= 6.28 |

Modules

No modules.

Resources

| Name | Type | |------|------| | awsbatchcomputeenvironment.this | resource | | awsbatchjobdefinition.this | resource | | awsbatchjobqueue.this | resource | | awsbatchschedulingpolicy.this | resource | | awsiaminstanceprofile.instance | resource | | awsiamrole.instance | resource | | awsiamrole.service | resource | | awsiamrole.spot_fleet | resource | | awsiamrolepolicyattachment.instance | resource | | awsiamrolepolicyattachment.service | resource | | awsiamrolepolicyattachment.spot_fleet | resource | | awsiampolicydocument.instance | data source | | awsiampolicydocument.service | data source | | awsiampolicydocument.spot_fleet | data source | | awspartition.current | data source |

Inputs

| Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | compute\environments | Map of compute environment definitions to create |

map(object({
name = optional(string)
name
prefix = optional(string)
computeresources = optional(object({
allocation
strategy = optional(string)
bidpercentage = optional(number)
desired
vcpus = optional(number)
ec2configuration = optional(list(object({
image
idoverride = optional(string)
image
type = optional(string)
})))
ec2keypair = optional(string)
instancerole = optional(string)
instance
types = optional(list(string))
launchtemplate = optional(object({
launch
templateid = optional(string)
launch
templatename = optional(string)
version = optional(string)
}))
max
vcpus = number
minvcpus = optional(number)
placement
group = optional(string)
securitygroupids = optional(list(string))
spotiamfleetrole = optional(string)
subnets = list(string)
tags = optional(map(string), {})
type = string
}))
eks
configuration = optional(object({
eksclusterarn = string
kubernetesnamespace = string
}))
service
role = optional(string)
state = optional(string)
tags = optional(map(string), {})
type = optional(string, "MANAGED")
updatepolicy = optional(object({
job
executiontimeoutminutes = number
terminatejobson_update = optional(bool, false)
}))
}))
| null | no | | create | Controls if resources should be created (affects nearly all resources) | bool | true | no | | create\instance\iam\_role | Determines whether a an IAM role is created or to use an existing IAM role | bool | true | no | | create\job\queues | Determines whether to create job queues | bool | true | no | | create\service\iam\_role | Determines whether a an IAM role is created or to use an existing IAM role | bool | true | no | | create\spot\fleet\iam\role | Determines whether a an IAM role is created or to use an existing IAM role | bool | false | no | | instance\iam\role\additional\policies | Additional policies to be added to the IAM role | map(string) | {} | no | | instance\iam\role\_description | Cluster instance IAM role description | string | null | no | | instance\iam\role\_name | Cluster instance IAM role name | string | null | no | | instance\iam\role\_path | Cluster instance IAM role path | string | null | no | | instance\iam\role\permissions\boundary | ARN of the policy that is used to set the permissions boundary for the IAM role | string | null | no | | instance\iam\role\_tags | A map of additional tags to add to the IAM role created | map(string) | {} | no | | instance\iam\role\use\name\prefix | Determines whether the IAM role name (instanceiamrolename) is used as a prefix | string | true | no | | job\definitions | Map of job definitions to create |
map(object({
container
properties = optional(string)
deregisteronnewrevision = optional(bool)
ecs
properties = optional(string)
eksproperties = optional(object({
pod
properties = object({
containers = map(object({
args = optional(list(string))
command = optional(list(string))
env = optional(map(string))
image = string
imagepullpolicy = optional(string)
name = optional(string) # Will fall back to use map key as container name
resources = object({
limits = optional(map(string))
requests = optional(map(string))
})
securitycontext = optional(object({
privileged = optional(bool)
read
onlyrootfilesystem = optional(bool)
run
asgroup = optional(number)
run
asnonroot = optional(bool)
runasuser = optional(number)
}))
volumemounts = optional(map(object({
mount
path = string
name = optional(string) # Will fall back to use map key as volume mount name
readonly = optional(bool)
})))
}))
})
dns
policy = optional(string)
hostnetwork = optional(bool)
image
pullsecrets = optional(list(object({
name = string
})))
init
containers = optional(map(object({
args = optional(list(string))
command = optional(list(string))
env = optional(map(string))
image = string
imagepullpolicy = optional(string)
name = optional(string) # Will fall back to use map key as init container name
resources = object({
limits = optional(map(string))
requests = optional(map(string))
})
securitycontext = optional(object({
privileged = optional(bool)
read
onlyrootfilesystem = optional(bool)
run
asgroup = optional(number)
run
asnonroot = optional(bool)
runasuser = optional(number)
}))
volumemounts = optional(map(object({
mount
path = string
name = optional(string) # Will fall back to use map key as volume mount name
readonly = optional(bool)
})))
})))
metadata = optional(object({
labels = optional(map(string))
}))
service
accountname = optional(string)
share
processnamespace = optional(bool)
volumes = optional(map(object({
empty
dir = optional(object({
medium = optional(string)
sizelimit = optional(string)
}))
host
path = optional(object({
path = string
}))
name = optional(string) # Will fall back to use map key as volume name
secret = optional(object({
optional = optional(bool)
secretname = string
}))
})))
}))
name = optional(string) # Will fall back to use map key as job definition name
node
properties = optional(string)
parameters = optional(map(string))
platformcapabilities = optional(list(string))
propagate
tags = optional(bool)
retrystrategy = optional(object({
attempts = optional(number)
evaluate
onexit = optional(map(object({
action = string
on
exitcode = optional(string)
on
reason = optional(string)
onstatusreason = optional(string)
})))
}))
schedulingpriority = optional(number)
tags = optional(map(string), {})
timeout = optional(object({
attempt
duration_seconds = optional(number)
}))
type = optional(string, "container")
}))
| null | no | | job\queues | Map of job queue and scheduling policy defintions to create |
map(object({
compute
environmentorder = map(object({
compute
environmentkey = string
order = optional(number) # Will fall back to use map key as order
}))
job
statetimelimitaction = optional(map(object({
action = optional(string, "CANCEL")
max
timeseconds = number
reason = optional(string)
state = optional(string, "RUNNABLE")
})))
name = optional(string) # Will fall back to use map key as queue name
priority = number
scheduling
policyarn = optional(string)
state = optional(string, "ENABLED")
tags = optional(map(string), {})
timeouts = optional(object({
create = optional(string, "10m")
update = optional(string, "10m")
delete = optional(string, "10m")
}))

# Scheduling policy
create
schedulingpolicy = optional(bool, true)
fair
sharepolicy = optional(object({
compute
reservation = optional(number)
sharedecayseconds = optional(number)
sharedistribution = optional(list(object({
share
identifier = string
weight_factor = optional(number)
})))
}))
}))
| null | no | | region | Region where the resource(s) will be managed. Defaults to the Region set in the provider configuration | string | null | no | | service\iam\role\additional\policies | Additional policies to be added to the IAM role | map(string) | {} | no | | service\iam\role\_description | Batch service IAM role description | string | null | no | | service\iam\role\_name | Batch service IAM role name | string | null | no | | service\iam\role\_path | Batch service IAM role path | string | null | no | | service\iam\role\permissions\boundary | ARN of the policy that is used to set the permissions boundary for the IAM role | string | null | no | | service\iam\role\_tags | A map of additional tags to add to the IAM role created | map(string) | {} | no | | service\iam\role\use\name\prefix | Determines whether the IAM role name (serviceiamrolename) is used as a prefix | bool | true | no | | spot\fleet\iam\role\additional\_policies | Additional policies to be added to the IAM role | map(string) | {} | no | | spot\fleet\iam\role\description | Spot fleet IAM role description | string | null | no | | spot\fleet\iam\role\name | Spot fleet IAM role name | string | null | no | | spot\fleet\iam\role\path | Spot fleet IAM role path | string | null | no | | spot\fleet\iam\role\permissions\_boundary | ARN of the policy that is used to set the permissions boundary for the IAM role | string | null | no | | spot\fleet\iam\role\tags | A map of additional tags to add to the IAM role created | map(string) | {} | no | | spot\fleet\iam\role\use\name\prefix | Determines whether the IAM role name (spotfleetiamrolename) is used as a prefix | string | true | no | | tags | A map of tags to add to all resources | map(string) | {} | no |

Outputs

| Name | Description | |------|-------------| | compute\_environments | Map of compute environments created and their associated attributes | | instance\iam\instance\profile\arn | ARN assigned by AWS to the instance profile | | instance\iam\instance\profile\id | Instance profile's ID | | instance\iam\instance\profile\unique | Stable and unique string identifying the IAM instance profile | | instance\iam\role\_arn | The Amazon Resource Name (ARN) specifying the IAM role | | instance\iam\role\_name | The name of the IAM role | | instance\iam\role\unique\id | Stable and unique string identifying the IAM role | | job\_definitions | Map of job defintions created and their associated attributes | | job\_queues | Map of job queues created and their associated attributes | | scheduling\_policies | Map of scheduling policies created and their associated attributes | | service\iam\role\_arn | The Amazon Resource Name (ARN) specifying the IAM role | | service\iam\role\_name | The name of the IAM role | | service\iam\role\unique\id | Stable and unique string identifying the IAM role | | spot\fleet\iam\role\arn | The Amazon Resource Name (ARN) specifying the IAM role | | spot\fleet\iam\role\name | The name of the IAM role | | spot\fleet\iam\role\unique\_id | Stable and unique string identifying the IAM role |

License

Apache-2.0 Licensed. See LICENSE.

🔗 More in this category

© 2026 GitRepoTrend · terraform-aws-modules/terraform-aws-batch · Updated daily from GitHub