Skip to content

Commit 8cec4e7

Browse files
feat!: Bump Terraform version to 1.0, and allow specifying compute environments for queue (#19)
Co-authored-by: Uziel David Sulkies <[email protected]>
1 parent 5da94b1 commit 8cec4e7

File tree

10 files changed

+34
-79
lines changed

10 files changed

+34
-79
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.77.0
3+
rev: v1.77.3
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_validate

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ module "batch" {
7070
state = "ENABLED"
7171
priority = 1
7272
73+
compute_environments = ["b_ec2_spot"]
74+
7375
tags = {
7476
JobQueue = "Low priority job queue"
7577
}
@@ -92,7 +94,7 @@ module "batch" {
9294
weight_factor = 0.2
9395
}]
9496
}
95-
97+
9698
tags = {
9799
JobQueue = "High priority job queue"
98100
}
@@ -161,14 +163,14 @@ Examples codified under the [`examples`](https://github.com/terraform-aws-module
161163

162164
| Name | Version |
163165
|------|---------|
164-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
165-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.30 |
166+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
167+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0 |
166168

167169
## Providers
168170

169171
| Name | Version |
170172
|------|---------|
171-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.30 |
173+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0 |
172174

173175
## Modules
174176

examples/ec2/README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,30 @@ Note that this example may create resources which will incur monetary charges on
2424

2525
| Name | Version |
2626
|------|---------|
27-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
28-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.30 |
27+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
28+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0 |
2929

3030
## Providers
3131

3232
| Name | Version |
3333
|------|---------|
34-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.30 |
34+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0 |
3535

3636
## Modules
3737

3838
| Name | Source | Version |
3939
|------|--------|---------|
4040
| <a name="module_batch"></a> [batch](#module\_batch) | ../.. | n/a |
4141
| <a name="module_batch_disabled"></a> [batch\_disabled](#module\_batch\_disabled) | ../.. | n/a |
42-
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
42+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 4.0 |
4343
| <a name="module_vpc_endpoint_security_group"></a> [vpc\_endpoint\_security\_group](#module\_vpc\_endpoint\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
44-
| <a name="module_vpc_endpoints"></a> [vpc\_endpoints](#module\_vpc\_endpoints) | terraform-aws-modules/vpc/aws//modules/vpc-endpoints | ~> 3.0 |
44+
| <a name="module_vpc_endpoints"></a> [vpc\_endpoints](#module\_vpc\_endpoints) | terraform-aws-modules/vpc/aws//modules/vpc-endpoints | ~> 4.0 |
4545

4646
## Resources
4747

4848
| Name | Type |
4949
|------|------|
5050
| [aws_cloudwatch_log_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource |
51-
| [aws_ami.ubuntu](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
5251
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
5352

5453
## Inputs

examples/ec2/main.tf

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -108,32 +108,6 @@ module "batch" {
108108
c_unmanaged = {
109109
name_prefix = "ec2_unmanaged"
110110
type = "UNMANAGED"
111-
112-
compute_resources = {
113-
type = "EC2"
114-
allocation_strategy = "BEST_FIT_PROGRESSIVE"
115-
116-
min_vcpus = 4
117-
max_vcpus = 16
118-
desired_vcpus = 4
119-
instance_types = ["m4.large", "m3.large", "r4.large", "r3.large"]
120-
121-
security_group_ids = [module.vpc_endpoint_security_group.security_group_id]
122-
subnets = module.vpc.private_subnets
123-
124-
ec2_configuration = {
125-
image_id_override = data.aws_ami.ubuntu.image_id
126-
}
127-
128-
# Note - any tag changes here will force compute environment replacement
129-
# which can lead to job queue conflicts. Only specify tags that will be static
130-
# for the lifetime of the compute environment
131-
tags = {
132-
# This will set the name on the Ec2 instances launched by this compute environment
133-
Name = "${local.name}-unmanaged"
134-
Type = "Ec2UnManaged"
135-
}
136-
}
137111
}
138112
}
139113

@@ -144,6 +118,8 @@ module "batch" {
144118
state = "ENABLED"
145119
priority = 1
146120

121+
compute_environments = ["b_ec2_spot"]
122+
147123
tags = {
148124
JobQueue = "Low priority job queue"
149125
}
@@ -225,7 +201,7 @@ module "batch" {
225201

226202
module "vpc" {
227203
source = "terraform-aws-modules/vpc/aws"
228-
version = "~> 3.0"
204+
version = "~> 4.0"
229205

230206
name = local.name
231207
cidr = "10.99.0.0/18"
@@ -234,20 +210,14 @@ module "vpc" {
234210
public_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"]
235211
private_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"]
236212

237-
enable_nat_gateway = true
238-
single_nat_gateway = true
239-
map_public_ip_on_launch = false
213+
enable_nat_gateway = true
214+
single_nat_gateway = true
240215

241216
public_route_table_tags = { Name = "${local.name}-public" }
242217
public_subnet_tags = { Name = "${local.name}-public" }
243218
private_route_table_tags = { Name = "${local.name}-private" }
244219
private_subnet_tags = { Name = "${local.name}-private" }
245220

246-
manage_default_security_group = true
247-
default_security_group_name = "${local.name}-default"
248-
default_security_group_ingress = []
249-
default_security_group_egress = []
250-
251221
enable_dhcp_options = true
252222
enable_dns_hostnames = true
253223
dhcp_options_domain_name = data.aws_region.current.name == "us-east-1" ? "ec2.internal" : "${data.aws_region.current.name}.compute.internal"
@@ -257,7 +227,7 @@ module "vpc" {
257227

258228
module "vpc_endpoints" {
259229
source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
260-
version = "~> 3.0"
230+
version = "~> 4.0"
261231

262232
vpc_id = module.vpc.vpc_id
263233
security_group_ids = [module.vpc_endpoint_security_group.security_group_id]
@@ -317,16 +287,6 @@ module "vpc_endpoint_security_group" {
317287
tags = local.tags
318288
}
319289

320-
data "aws_ami" "ubuntu" {
321-
owners = ["099720109477"]
322-
most_recent = true
323-
324-
filter {
325-
name = "name"
326-
values = ["ubuntu/images/hvm-ssd/ubuntu-*-20.04-amd64-server-*"]
327-
}
328-
}
329-
330290
resource "aws_cloudwatch_log_group" "this" {
331291
name = "/aws/batch/${local.name}"
332292
retention_in_days = 1

examples/ec2/versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 0.13.1"
2+
required_version = ">= 1.0"
33

44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 3.30"
7+
version = ">= 4.0"
88
}
99
}
1010
}

examples/fargate/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,24 @@ Note that this example may create resources which will incur monetary charges on
2424

2525
| Name | Version |
2626
|------|---------|
27-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
28-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.30 |
27+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
28+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0 |
2929

3030
## Providers
3131

3232
| Name | Version |
3333
|------|---------|
34-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.30 |
34+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0 |
3535

3636
## Modules
3737

3838
| Name | Source | Version |
3939
|------|--------|---------|
4040
| <a name="module_batch"></a> [batch](#module\_batch) | ../.. | n/a |
4141
| <a name="module_batch_disabled"></a> [batch\_disabled](#module\_batch\_disabled) | ../.. | n/a |
42-
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
42+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 4.0 |
4343
| <a name="module_vpc_endpoint_security_group"></a> [vpc\_endpoint\_security\_group](#module\_vpc\_endpoint\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
44-
| <a name="module_vpc_endpoints"></a> [vpc\_endpoints](#module\_vpc\_endpoints) | terraform-aws-modules/vpc/aws//modules/vpc-endpoints | ~> 3.0 |
44+
| <a name="module_vpc_endpoints"></a> [vpc\_endpoints](#module\_vpc\_endpoints) | terraform-aws-modules/vpc/aws//modules/vpc-endpoints | ~> 4.0 |
4545

4646
## Resources
4747

examples/fargate/main.tf

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ module "batch" {
173173

174174
module "vpc" {
175175
source = "terraform-aws-modules/vpc/aws"
176-
version = "~> 3.0"
176+
version = "~> 4.0"
177177

178178
name = local.name
179179
cidr = "10.99.0.0/18"
@@ -182,20 +182,14 @@ module "vpc" {
182182
public_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"]
183183
private_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"]
184184

185-
enable_nat_gateway = true
186-
single_nat_gateway = true
187-
map_public_ip_on_launch = false
185+
enable_nat_gateway = true
186+
single_nat_gateway = true
188187

189188
public_route_table_tags = { Name = "${local.name}-public" }
190189
public_subnet_tags = { Name = "${local.name}-public" }
191190
private_route_table_tags = { Name = "${local.name}-private" }
192191
private_subnet_tags = { Name = "${local.name}-private" }
193192

194-
manage_default_security_group = true
195-
default_security_group_name = "${local.name}-default"
196-
default_security_group_ingress = []
197-
default_security_group_egress = []
198-
199193
enable_dhcp_options = true
200194
enable_dns_hostnames = true
201195
dhcp_options_domain_name = data.aws_region.current.name == "us-east-1" ? "ec2.internal" : "${data.aws_region.current.name}.compute.internal"
@@ -205,7 +199,7 @@ module "vpc" {
205199

206200
module "vpc_endpoints" {
207201
source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
208-
version = "~> 3.0"
202+
version = "~> 4.0"
209203

210204
vpc_id = module.vpc.vpc_id
211205
security_group_ids = [module.vpc_endpoint_security_group.security_group_id]

examples/fargate/versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 0.13.1"
2+
required_version = ">= 1.0"
33

44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 3.30"
7+
version = ">= 4.0"
88
}
99
}
1010
}

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ resource "aws_batch_job_queue" "this" {
228228
state = each.value.state
229229
priority = each.value.priority
230230
scheduling_policy_arn = try(each.value.create_scheduling_policy, true) ? aws_batch_scheduling_policy.this[each.key].arn : try(each.value.scheduling_policy_arn, null)
231-
compute_environments = [for env in aws_batch_compute_environment.this : env.arn]
231+
compute_environments = slice([for env in try(each.value.compute_environments, keys(var.compute_environments)) : aws_batch_compute_environment.this[env].arn], 0, min(length(try(each.value.compute_environments, keys(var.compute_environments))), 3))
232232

233233
tags = merge(var.tags, lookup(each.value, "tags", {}))
234234
}

versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 0.13.1"
2+
required_version = ">= 1.0"
33

44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 3.30"
7+
version = ">= 4.0"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)